GUI node not recieving input

Hi, im having a issue with a level selection screen menu for a game i made. For the level selection screen the GUI node is not receiving any input and i have no idea why.

I have 3 scripts, the loader script, the main menu script and the script for my level selection menu. The main menu script works fine and the loader works as it loads the main menu and loads the level selection menu but when i press “level 1” nothing happens

function load_levelmenu(self)  --  Code for my level 1 
	msg.post(".", "acquire_input_focus")
	print("hello2") -- checking if anything happens
end

function on_input(self, action_id, action) --Loading the level
	if(action_id and gui.get_node("level1")) then -- When node is selected Level starts
		if(gui.pick_node(level1,action.x,action.y)) then
			msg.post("loader:/go#loader", "level1")--
		end
	end
-- Loader script 
local function load_menu(self) --Load menu collection
	msg.post("go#mainmenu", "load")
	msg.post("go#mainmenu", "enable")
end
local function unload_menu(self) -- 
	msg.post("go#mainmenu","unload")
end
local function load_main(self) --This loads main collection 
	msg.post("go#main", "load")
	msg.post("go#main", "enable")
end
local function load_levelmenu(self) ---load the level select
	msg.post("go#levelmenu", "load")
	msg.post("go#levelmenu", "enable")
	msg.post("go#mainmenu", "disable") ----*
end
local function unload_levelmenu(self)
	msg.post("go#levelmenu", "unload")
end
function init(self)
	msg.post(".", "acquire_input_focus") 
	load_menu(self) --Loads menu when game starts
end

function on_message(self, message_id, message, sender)
	if message_id == hash("level1") then
		load_main(self)
		unload_levelmenu(self) 
	end
end

function on_message(self, message_id, message, sender) ---Load actual level
	if message_id == hash ("load_level") then
		unload_levelmenu(self)
	end
end
function on_message(self, message_id, message, sender)
	if message_id == hash ("begingame") then
		load_levelmenu(self)
		unload_menu(self)
	end
end
-- Main menu script
 function init(self)
	msg.post(".", "acquire_input_focus")
end


function on_input(self, action_id, action) --Loading the level
	if(action_id == hash("touch") and action.released == true) then
		local textBegin = gui.get_node("begingame") --
		if(gui.pick_node(textBegin,action.x,action.y)) then
			msg.post("loader:/go#loader", "begingame") -- starts game
			print("hello")
		end
	end
	-- exits out the game
	if(action_id == hash("touch") and action.released == true) then
		local textExit = gui.get_node("exitgame")
		if(gui.pick_node(textExit,action.x,action.y)) then
			msg.post("@system:", "exit", {code = 0}) --This exits the game
		end
	end    
end

i have attached all 3 scripts just so you can kinda understand my code a bit more

The script handling collection proxies needs to acquire input focus as well

-- Level selection script

function on_input(self, action_id, action) --Loading the level
	if(action_id and gui.get_node("level1")) then -- When node is selected Level starts
		if(gui.pick_node(level1,action.x,action.y)) then
			...

This isn’t how you check for the user clicking on a GUI node. You got it right in your main menu script:

function on_input(self, action_id, action) --Loading the level
	if(action_id == hash("touch") and action.released == true) then
		local textBegin = gui.get_node("begingame") --
		if(gui.pick_node(textBegin,action.x,action.y)) then
			...

You also have multiple on_message() functions defined in your loader script, which doesn’t work; only the last one (the one that checks for "begingame" in this case) will be executed. You have to combine them into one function like so:

function on_message(self, message_id, message, sender)
	if message_id == hash("level1") then
		load_main(self)
		unload_levelmenu(self) 
	elseif message_id == hash ("load_level") then
		unload_levelmenu(self)
	elseif message_id == hash ("begingame") then
		load_levelmenu(self)
		unload_menu(self)
	end
end
2 Likes

I added the code you wrote, however my level menu node still doesnt recieve any input.
I added a print statement to see if anything happens and still nothing happens

function load_levelmenu(self)  -- Loads the level menu GUI
	msg.post(".", "acquire_input_focus")
end

function on_input(self, action_id, action) --Loading the level
	if(action_id == hash("touch") and action.released == true) then
		local textBegin = gui.get_node("level1") --
		if(gui.pick_node(textBegin,action.x,action.y)) then
			print("Hello2")
		end
	end
end

Nevermind i fixed it

function init(self)
	msg.post(".", "acquire_input_focus")
end

function on_input(self, action_id, action) --Loading the level
	msg.post(".", "acquire_input_focus")
	if(action_id == hash("touch") and action.released == true) then
		local textlevel = gui.get_node("level1") --
		if(gui.pick_node(textlevel,action.x,action.y)) then
			msg.post("loader:/go#loader", "level1")
		end
	end
end

Was missing the init function at the beginning

1 Like