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

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By dezekeerjoran
:warning: Old Version Published before Godot 3 was released.

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

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 :expressionless:

Zylann | 2016-12-21 01:29

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

dezekeerjoran | 2016-12-21 11:01

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.

Zylann | 2016-12-21 13:36

ho, oke thanks:)

dezekeerjoran | 2016-12-21 13:54

:bust_in_silhouette: Reply From: ingo_nikot

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?

_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…

Zylann | 2016-12-21 13:39

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.

ingo_nikot | 2016-12-21 21:36

:bust_in_silhouette: Reply From: eons

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