I want to make a text from a Label change from "A" to "B" when a variable changes to "2".

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Bagasito

I do not want it to be the variable: I want it to change to another pre-set text. I’ve tried many times, in many different ways, coming across the nothingness of the class_name that doesn’t work just to use something, but I can’t get any results. If I put simply an if outside of a func _process(_delta), it doesn’t check forever, but if I do put it inside the said func _process(_delta), it bugs and inspires my anger towards the binary code in my screen, even if I put the code inside the Label node together with the variable I want.

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