0 votes

how can you make a event happen when a label is a certain word?

in Engine by (55 points)

Can you give more details?
If you are really talking about Label, then... you could do:

if label.get_text() == "Word":
    do_stuff()`

But that's not an event, a Label is not interactive, hence my question :|

thanks, it works. But i don't really what you mean with 'not interactive' and not an event.
still thank you.

It's not interactive because a Label only shows text, it doesn't require user input. It's also not an event because nothing else causes the label to change, it's just you (programmer) that sets its value. Something the user is doing will trigger an event (text entered, mouse moved, key pressed), and for example LineEdit does that. But Labels are static, they don't handle such a thing.

ho, oke thanks:)

2 Answers

+2 votes
Best answer

draw will be fired if you change the text of the label:

yourLabel.connect("draw",self,"check_word",[yourLabel])
yourLabel.set_text("word")

...

func check_word(lbl)
  if lbl.get_text() == "word":
    print(bingo)

but i think its better to just check when you call "set_text". can you explain why you need that case?

by (295 points)
selected by

_draw is not even a good solution because it will be triggered a lot more times than just text change. It will be called when the label is shown, hidden, when it is moved, when its color or font is changed etc...

i agree, thats why i said its better to check the word just after set_text manually.

but if the askser insists on events, draw is the only work-around that always will get called on changes.

+1 vote

Override set_text on the Label script

func set_text(text):
    .set_text(text) #super set_text
    if text == event_trigger_text: 
        pass #do something here
by (7,946 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.