0 votes

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 classname 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.

in Engine by (12 points)

1 Answer

+1 vote

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.

by (16,676 points)

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.

didn't work at all, haven't seen anger however.

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

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.

enter image description here

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

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.

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.