# Messaging a gui before it's laoded

**URL:** <https://forum.defold.com/t/messaging-a-gui-before-its-laoded/72693>\
**Category:** Questions\
**Created:** [February 19, 2023, 7:24pm UTC](https://forum.defold.com/t/messaging-a-gui-before-its-laoded/72693 "2023-02-19T19:24:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cyion](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/cyion/32/30777_2.png) [@Cyion](https://forum.defold.com/u/Cyion)\
**Post date:** [February 19, 2023, 7:24pm UTC](https://forum.defold.com/t/messaging-a-gui-before-its-laoded/72693/1 "2023-02-19T19:24:01Z")

</div>

I’ve got a problem where i’m passing a message and loading a gui from the loader script in the same function resulting in both things being executed in the same frame. This has resulted in the gui being messaged before the gui has been enabled/loaded. Does anyone know how i can message the gui after it has been loaded.

This code below both recieves the message which will be passed to the gui and also passes a message to the loader script to call for the gui to be loaded:

```lua
	if message_id == hash("game_complete") then
		self.timer = message[timer]
		unload_game(self)
		load_level_complete(self)
	end

```

At the moment this function both loads and sends the message to the gui

```lua
local function load_level_complete(self)
	msg.post("go#level_complete", "load")
	msg.post("go#level_complete", "enable")
	msg.post("level_completed:/level_completed#level_completed", "time", {timer = self.timer})
end

```

How can i split the message from the line that gets the gui to load so that the gui can recieve the message after it has loaded

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [February 19, 2023, 7:52pm UTC](https://forum.defold.com/t/messaging-a-gui-before-its-laoded/72693/2 "2023-02-19T19:52:07Z")

</div>

> [@Cyion](#):
>
> ```lua
> local function load_level_complete(self)
> msg.post("go#level_complete", "load")
> msg.post("go#level_complete", "enable")
> msg.post("level_completed:/level_completed#level_completed", "time", {timer = self.timer})
> end
> 
> ```

That doesn’t work. Sending a message is asynchronous, and loading a collection is also synchronous. You can’t do anything with a loaded collection until you receive a “proxy\_loaded” message. This means that you have to deal with this in stages. First you load and wait for proxy\_loaded, then you enable, and then in the next frame you can send a message.

Have a look at this example:

> **[Proxy](https://defold.com/examples/collection/proxy/)**
>
> This example shows how to use collection proxies to load and unload collections.
