Why doesn't my variable effect another in another script

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

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

Using Godot 3.0beta1

ItemBuy.gd:

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():
    pass

# The Buy Button
func _on_Button_pressed():
    if (counter.powerCandy == false):
        counter.powerCandy = true
        print("Candy Bought!")
        self.set_text("Bought!")
        
func _on_Timer_timeout():
    # Add money!
    if (counter.powerCandy == true):
        counterInt += 10
        print("Added money (Candy)")

RichLabelScript.gd:

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.
    set_process_input(true)
    self.set_text("Money: $0")
    

func _process(delta):
    # Tap, Gain, Repeat...
    var press = Input.is_action_pressed("Press")
    
    if press and not pressed:
        print("Tap")
        counter += 1
        self.clear()
        self.add_text(str("Money: $", counter)) 
    pressed = press


func _on_Timer_timeout():
    counter =+ 1
    self.clear()
    self.add_text(str("Money: $", counter))
:bust_in_silhouette: Reply From: hilfazer

Hi,

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.

You were slightly correct;

I had to change “counterInt” to “counter.counter”

Anyways, it’s fixed!

HarryCourt | 2017-12-03 12:21