Label Text Not Updating

Hello! I’m still fairly new to Godot, and I don’t understand why the text for my Label won’t update.

Here is the code from my Autoload scene:

@export var value = Label

func sanddollar_caught():
	sanddollar += 1
	print(sanddollar) #testing
	value.text = str(sanddollar)
	print(value.text) #testing

I’m trying to call the function to update the label text for value, and it isn’t a problem with the function not being called as both print commands work (with their correct values), but even though it’s printing value.text correctly as the updated value, the displayed text isn’t.

Loading value.text works fine (displays “2” but stays as “2” after sanddollar_caught function is called)

func load_data():
	if FileAccess.file_exists(save_path):
		var file = FileAccess.open(save_path, FileAccess.READ)
		var stored_data = file.get_var()
		print(stored_data)
		value.text = stored_data.get("valuetext", "0")
		value.text = "2" #testing
		fish1 = stored_data.get("fish1", [])
		sanddollar = int(value.text)
		print("Loaded")

func _ready():
	load_data()

Sounds like the label isnt visible in your scene and you are seeing a different label, which is not from the autoload.

Can you show your scene setup?

The label I’m trying to edit is sanddollar_score > scoreboard > value, and the main node MainScene is my Autoload script, and I’m trying to call the function in Control2 > Fishing... script


May i ask which scene you run when you start the game?

MainScene

So you have it as autoload aswell as run it as your game-Scene?

This means you are loading this scene twice. You can run your game and then click on “Remote” in the godot editor and see your game-scene-tree. There should be two MainScene-nodes which are basically a copy of each other.

i suggest to remove the autoload main-scene and just keep the MainScene as your main-loaded scene and see what happens

How do I just remove the Autoload-MainScene (@Node@2)? Are you saying I should transfer my code into a different scene and assign that as the autoload instead?

No got to your project settings and remove MainScene from the autoloads

But I need some of the variables from MainScene in my other scenes? That’s why I needed it to be an Autoload.

you can make these variables “static”. This is similar to autoload but just for specific variables

class_name MainScene extends Node

static var my_variable: int = 0

func _ready():
    MainScene.my_variable = 5

(You need a class_name for it to work)

1 Like

Thank you! This helped a lot!

1 Like