Game won't pause. Please Help (SOLVED)

Game will not pause when the pause button is clicked. I am very new to the game engine. I’ve tried following the “input” tutorial.

Reef Cleaner.zip (4.9 MB)

I haven’t looked at the included project yet. How do you implement the pause functionality?

Did you check this example: https://github.com/britzl/publicexamples/tree/master/examples/pause_game ?

Yes, my team has looked at the example that you have suggested. We still have not worked this problem out. Looking at the project might help you more than me trying to explain how we are implementing the pause menu. (We are fresh programmers. I’m sorry) Thank you for the help that you are giving.

is there a way to “freeze” the game without having a proxy?

Nope, not an easy one. That’s the intended way to pause things with Defold.


I looked through your project. You’re just not sending the “set_time_step” message where it needs to go (to the collection proxy).

This is the relevant part of your hierarchy, in your main.collection.

  • main (main.collection)
    • main (game object)
      • gui (main.gui)
      • main (main.script)

With your gui—the one with the pause button—you successfully get a touch pressed input (which you can test with print statements), and when that happens you send a “set_time_step” message to the relative address, “#main”.

-- Your code:
function on_input(self, action_id, action)
	if action_id == hash("touch") and action.pressed then
		local pausenode = gui.get_node("pause") 
		if gui.pick_node(pausenode, action.x, action.y)then
			msg.post("UI", "enable")
		end	
		msg.post("#main", "set_time_step", {factor = 0, mode = 1})
	end
end

The address “#main” is relative: you’re not specifying the socket or the path, so it refers to the component named “main” on the current game object. So that means it gets sent to your “main” script on the same object. If you open that script, it’s on_message function is empty, so it does nothing. And that’s the end of it.

If you put “print(message_id)” inside that function, you will see that it gets a “set_time_step” message whenever you click on the screen while the game is running.

What you need to do is get that message to the collection proxy component for your main.collection.

If you check the URL of your loader script (in the collection & on the game object where the collection proxy is located), using:

print(msg.url())

You’ll get: “DEBUG:SCRIPT: url: [loader:/go#loader]”
This should give you a hint of what the complete URL of the collection proxy component is. Just replace the component name (the bit after the #). So, going back to your main.gui_script that is supposed to be pausing the game, all you have to do is replace the URL “#main” with “loader:/go#main”, and bingo! It pauses the game.


…Unfortunately this leaves you with no way to un-pause it again. :smiley:

2 Likes

Oh, and I just want to say. This isn’t that surprising or unusual of a mistake. The addressing and message passing system takes some getting used to. Just keep reading the addressing manual, look at the “URL” property of objects in the editor, and check things with “print(msg.url())”.

2 Likes

Thank you! Time to work on the unpause haha :slight_smile: