0 votes

Why doesn't the RichLabelText not change when I change an int in another script? I'm out of ideas.

Using Godot 3.0beta1


extends Button

# Variables
onready var counter = get_node("/root/World/Counter")
onready var counterInt = get_node("/root/World/Counter").get("counter")
onready var timer = get_node("/root/World/Counter").get("timer")

func _ready():

# The Buy Button
func _on_Button_pressed():
    if (counter.powerCandy == false):
        counter.powerCandy = true
        print("Candy Bought!")

func _on_Timer_timeout():
    # Add money!
    if (counter.powerCandy == true):
        counterInt += 10
        print("Added money (Candy)")


extends RichTextLabel

# Things that actually make the game work
onready var counter = 0
onready var timer = 0
onready var pressed = false

# Power Up Varibles
onready var powerSign = false
onready var powerCards = false
onready var powerEmployees = false
onready var powerDrinks = false
onready var powerCandy = false

func _ready():
    # Tell what to do when the "Play" button is pressed.
    self.set_text("Money: $0")

func _process(delta):
    # Tap, Gain, Repeat...
    var press = Input.is_action_pressed("Press")

    if press and not pressed:
        counter += 1
        self.add_text(str("Money: $", counter)) 
    pressed = press

func _on_Timer_timeout():
    counter =+ 1
    self.add_text(str("Money: $", counter))
asked Dec 3, 2017 in Engine by HarryCourt (162 points)

1 Answer

0 votes
Best answer


value of 'counter' is copied into 'counterInt', it is not a reference. By changing 'counterInt' you will not be at the same time changing 'counter' from RichLabelScript.gd.

Try something like
counter.counter = counterInt
after you change your counterInt.

answered Dec 3, 2017 by hilfazer (2,112 points)
selected Dec 3, 2017 by HarryCourt

You were slightly correct;

I had to change "counterInt" to "counter.counter"

Anyways, it's fixed!

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 How to use this Q&A? before posting your first questions.