How to pass variable from gui_script to main function? (SOLVED)

Hi and welcome!

This is probably easiest made with message passing. You could also maybe use a shared Lua module, but this is what message passing is for!

Given that your script is called main and is in a game object named go (like the image)

You can then do msg.post("/go#main", "start") in your .gui_script

And in your .script you would check for it in the on_message

function on_message(self, message_id, message, sender)
  if message_id == hash("start") then
    -- Game should start
  end
end
3 Likes