|
|
|
|
Reply From: |
jgodfrey |
This is a very vague description of what you’re trying to do but it sounds as simple as this:
var some_var
func _ready():
$Label.text = "A"
func _process(delta):
if some_var == 2:
$Label.text = "B"
As soon as something set the value of some_var
to 2
, the label’s text will change to B
.
mine $Label appears black green, not like yours. It doesn’t work. solution, something in the code itself, probably. I will try on a different project. Thank you.
Bagasito | 2022-11-29 23:23
didn’t work at all, haven’t seen anger however.
Bagasito | 2022-11-29 23:31
did I try get_node()? yes. actually I tried your method before but I retried for only God knows when it might start working correctly
Bagasito | 2022-11-29 23:35
This is a really straight forward problem and should be easy to resolve. The best way to get a resolution is for you to show the code you have so someone can assist you in finding the problem with it.
Post the relevant code and I’m sure the problem can be fixed.
jgodfrey | 2022-11-29 23:43
Bagasito | 2022-12-02 17:44
Based on your scene tree, the Button
and Label
are siblings with a common parent (the Node2D
), right? And, the script you show is attached to the Button
?
In that case, your $Label
references in the script won’t work (and should be generating errors when you run the game).
A references of $Label
will cause the engine to search for a control with that name as a child of the node containing the script (so, as a child of Button
). In this case, that node won’t be found.
To find a sibling node, you need to reference it differently. This should work:
extends Button
var cenoura = 0
onready var label = get_node("../Label")
func _ready():
label.text = "BATATA"
func _process(delta):
if cenoura == 1:
label.text = "CENOURA"
func _on_Button_pressed():
cenoura = 1
jgodfrey | 2022-12-02 17:58
good enough I said I wasn’t angry anymore otherwise I would be both dumb and an idiot, now I’m just dumb, thank you.
Bagasito | 2022-12-03 15:18