In the game i’m making ive got a timer set that is used to time how long it takes for the player the complete the level, i would then like the time to be displayed on a gui that says level complete with the time.
So i have coded my game to: send the time (self.timer) to the loader script which will then display the gui with the time.
So below is the code that sends the time to the loader script:
This is the code in the loader that sends the time to the gui and gets the gui to run:
if message_id == hash("game_complete") then
unload_game(self)
self.timer = message[timer]
load_level_complete(self)
local function load_level_complete(self)
msg.post("/level_complete#level_complete", "timer", {timer = self.timer})
msg.post("go#level_complete", "load")
msg.post("go#level_complete", "enable")
end
end
I’ve got 2 errors:
the first is caused when i assign self.timer = 0 in the init function of the loader. I’m not sure why it does this nor how i should fix it. (Do i even need to assign self.timer in the init function?)
the second is caused by an improper url when i want to send the time to the gui from the loader. I didn’t see any problem with the URL so i’m not sure what is causing it?
ims till using the function below to send the message:
local function load_level_complete(self)
msg.post("go#level_complete", "load")
msg.post("go#level_complete", "enable")
msg.post("level_complete:/level_complete#level_complete", "timer", {timer = self.timer})
end
When i got it to print the URL it gave me:
Which is the same as the 1 in the function but i’m now getting the error:
Is go#level_complete the collection proxy for level_complete? In that case you probably need to wait for the proxy to actually be enabled. This means you can’t send the “timer” message in the same frame as you send load and enable.