Press the button, change the text (SOLVED)

Kinda new in Defold. Here’s a simple question:
What is easiest way to change text of the node by pressing, say, enter key.
As far as i understand, i should do next:

  1. create .gui with text node

  2. bind key_enter to action

  3. create script file and add it to the go

  4. add this line to init function (to listen to the input):
    msg.post(".", “acquire_input_focus”)

  5. theeen, i don’t know, add this lines to on_input function:
    if action_id == hash(“chtext1”) and action.value == 1 then
    local node1 = gui.get_node(“text1”)
    gui.set_text(node1, “changed text”)
    end

it doesn’t work though. i think i fail to understand some core stuff here.

btw, chtext1 is my action name for enter key, text1 is text node name

You need to change step 3 a bit; you need to create a gui_script and add it to your GUI, not a regular GO script.

Specify the gui script for a GUI in the properties view when having the root GUI node selected in the outline:

Otherwise the code looked like it should work! :slight_smile:

1 Like

Thanks, sven, it works like magic.

1 Like