This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+1 vote

Hi all. I am trying to link the real-time score variable count to all scenes/nodes but putting the variable in the global script alone doesn't seem to work.

In the global script:

var score = 0

In the menu/score-keeping/leaderboard script (this works fine):

func _on_Player_scored():
global.score += 1

In main scene script: Spawn mobs when the player is still below or above a certain score. This does not work as the global.score on the main script stays 0 even when the player is scoring.

Vice versa. I tried the opposite way; connect the player_scored signal to the main script and its mob-spawning function works but the score count label on the menu script stays 0 instead.

The only way I can get the score to count on both sides is to connect the Player_scored signal on both scripts but I'm sure there's a better way to do this.

Appreciate it if anyone could advise. Thanks!

Godot version 3.3.4
in Engine by (29 points)

Have you added the script as a Singleton and enabled Global Variable?
Project Settings > AutoLoad

Yes that has been done.
Is it not working because one script's node is the child of another?

Sorry for the late reply, did you try incrementing the global score variable on process then going to the Remote part in Scene tab while the game is running and checking if singleton's score variable is getting incremented?
It should be the first node after root.

Please log in or register to answer this question.

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.