Post msg to GUI script and also how prevent Propagation inputs

Hello all
after reading this : relative-addressing
and this GUI
I have simple scene ( from mobile example ) on top of this i added GUI collection with script that should capture only the button on the GUI collection .
but i have 2 problems
1 .when i click the button on the GUI collection the event propagate also to the main collection .
which i like prevent .
and when i click on the main.collection icon it propagate to the GUI collection .
This is i want to prevent . each button will handle its own event without Propagation .
2. I try to send massage to the GUI collection so it will hide . but i can’t find how to call the gui collection
i try to :

msg.post("guis#box_button_parent","hide_level_select")
msg.post("#box_button_parent","hide_level_select") 

But i gives me error :

ERROR:GAMEOBJECT: Component ‘/guis#box_button_parent’ could not be found when dispatching message ‘hide_level_select’ sent from main:/go#main

This is my main script :

    function init(self)
    	msg.post(".", "acquire_input_focus")
    	msg.post("@render:", "use_fixed_fit_projection", { near = -1, far = 1 })
    end

    function on_input(self, action_id, action)
    	if action_id == hash("touch") and action.pressed then
    		print("Touch!")
    		msg.post("guis#box_button_parent","hide_level_select")
    	end
    end

And this is my level_select.gui → select_level.gui_script

    function init(self)

    	msg.post(".","acquire_input_focus")
    	msg.post("#","show_level_select")
    	self.active = false
    	
    end



    function on_message(self, message_id, message, sender)
    	if message_id == hash("show_level_select") then 
    		msg.post("#","enable")
    		self.active = true
    	elseif message_id == hash("hide_level_select") then 
    		msg.post("#","disable")
    		self.active = false
    	end
    end

    function on_input(self, action_id, action)
    	if action_id == hash("touch") and action.pressed and self.active then 
    		print("button pressed1111")
    	end
    end

also when i add “return true” in the select_level.gui_script on_input function
like this:

       function on_input(self, action_id, action)
        	if action_id == hash("touch") and action.pressed and self.active then 
        		print("button pressed1111")
                     return true
        	end
        end

it prevent me to capture the on_input from the main.script …

Here is the root nootdi try to msg to from main script:

Thanks for help .

UPDATE
Found how to post msg like this:

msg.post(“main:/guis#level_select”, “hide_level_select”)

But the question with "prevent Propagation " still not solved

If I remember correctly, your on_input() must return true for it to eat the input.

see my update ,if i set true the main collation stop receiving ,and i dont want this

You might need to check if the touch is on the button or not, if yes, do the button action and stop propagation by return true, if no, do nothing for the button.

So, to archive that you should use gui.pick_node()

Your code at on_input should be like:

if action_id == hash("touch") and action.pressed and gui.pick_node(gui.get_node("1_bg"), action.x, action.y) then 
	print("button pressed1111")
	return true
end
2 Likes