I cant make gui button

Script didnt work when i click on gui element

function on_input(self,action_id, action)
if action_id == hash("touch") and gui.pick_node(gui.get_node("play"), x, y) then
    print("ia")
end
end

Three things to verify;

  1. In your init() function, are you acquiring the input? Like this: msg.post(".", "acquire_input_focus")
  2. In your input_binding file, do you have a mouse_trigger with the name “touch”?
  3. Is your gui_script set on the GUI? Click the GUI node in the outline and check for “Script” entry.

edit: Check what @sicher said first. :slight_smile:

1 Like

You mention x and y in your code. It should be action.x and action.y:

function on_input(self,action_id, action)
    if action_id == hash("touch") and gui.pick_node(gui.get_node("play"), action.x, action.y) then
        print("ia")
    end
end
2 Likes

Can you give example with photos because my gui element didnt react on my actions? I saw in my script and i put there init function and after that nothing happened.

Yup, this is the solution. Use action.x and action.y, not x and y alone.

2 Likes

I changed and after that nothing happened

Can you put a print() in on_input() and see if you get any input to your gui script? Please also post the on_input() part of the script here again.

function init(self)
msg.post(".", "acquire_input_focus")
end
function on_input(self,action_id, action)
    if action_id == hash("touch") and gui.pick_node(gui.get_node("play"), action.x, action.y) then
       msg.post("gui#level", "load") 
       print("Aalex")
    end
end

If you put a print() in the init() function, do you see the output in the console when you run?

Yes i see text.

Then “load” is definitely sent to gui#level. The problem is not in this script.




Where is the problem?

Problem is “main.script”. When a proxy loads it sends “proxy_loaded” back to the script that sent it “load”, which in your case is “main_menu.gui_script”.

So the code you have in “main.script” should be in “main_menu.gui_script”.

1 Like

So i put my code from main script in gui script and nothing changed? I need to destroi previous code from main_menu.gui_script or not?

Move the on_message() code to main_menu.gui_script.

EDIT: The important thing is that the script that sends “load” to the proxy needs to listen to “proxy_loaded” message in an on_message() function and do the init and enable of the loaded proxy collection.

Like this

Nothing changed. The button still is unclickable

I’ve created an example of a menu and a game collection being loaded and unloaded via a controller script. You can see it in action here:

http://britzl.github.io/publicexamples/menu_and_game/index.html

And the code here:

2 Likes

How does your input binding file look?

1 Like