Choosing options on GUI when paused

I’m pausing my game using

msg.post("loader:/go#main", "set_time_step", {factor = 1, mode = 1})

and then I’m enabling my nodes on the gui
player script section:

if action_id == hash("p") then
		if action.released then
			if self.pause then
				self.pause = false
				print("Unpause")
				msg.post("loader:/go#main", "set_time_step", {factor = 1, mode = 1})
				msg.post("main:/go#pause", "unPause")
			else
				print("Pause")
				msg.post("loader:/go#main", "set_time_step", {factor = 0, mode = 1})
				self.pause = true
				msg.post("main:/go#pause", "pause")
			end
		end
	end

pause.gui_script:

function init(self)
	print(msg.url())
	-- Disable the "box" GUI element at the start of the game
	gui.set_enabled(gui.get_node("box"), false)
	gui.set_enabled(gui.get_node("resume"), false)
	gui.set_enabled(gui.get_node("exitMainMenu"), false)
	gui.set_enabled(gui.get_node("help"), false)
end

function on_message(self, message_id, message, sender)
	if message_id == hash("pause") then
		gui.set_enabled(gui.get_node("box"), true)
		gui.set_enabled(gui.get_node("resume"), true)
		gui.set_enabled(gui.get_node("exitMainMenu"), true)
		gui.set_enabled(gui.get_node("help"), true)
	end
	if message_id == hash("unPause") then
		gui.set_enabled(gui.get_node("box"), false)
		gui.set_enabled(gui.get_node("resume"), false)
		gui.set_enabled(gui.get_node("exitMainMenu"), false)
		gui.set_enabled(gui.get_node("help"), false)
	end

	if (action_id == hash("left_click") and action.released == true) then
		print("click")
		local resume = gui.get_node("resume")
		if(gui.pick_node(resume,action.x,action.y)) then
			print("resume")
			--msg.post("loader:/go#main", "set_time_step", {factor = 1, mode = 1})
			msg.post("/Player#player_scrips_v2", "unPause")
		end
	end
end

i can pause it easily by just pressing p and the pause menu shows and dissapears when its paused and unpaused but I also want to be able to click the buttons on my pause menu but when i try clicking resume it does nothing
I have checked and nothing is printed in the console when i click resume.
Is there any way around this?

The code references action_id and action variables in your on_message function where they are undefined.

Create the on_input function and move your mouse click check code into that.

2 Likes

Thankyou, that fixed it. I had also forgotten to add

	msg.post(".", "acquire_input_focus")

at the start as well