0 votes

Hello, I am trying to use custom signals to pass variable speed from one scene into a singleton and then have player scene use this singleton for the speed.

Currently I have in CharacterSheet.gd:

signal speed_signal(speed)

signal", getnode("/root/DataImport"), "PlayerStats")

func process(delta):
signal("speed_signal", speed)

DataImport.gd (singleton)
var speed = 300

func Player_Stats(speed):

So the thing I am trying to figure out is print(speed) returns the correct speed values from the CharacterSheet.gd, but var speed stays at 300 when it gets grabbed by the Player scene. And if I dont assign a default value for the var speed it just grabs nil/0/error and not the value I have under func Played_Stats(speed)

Any help appreciated.

in Engine by (51 points)

1 Answer

+1 vote
Best answer

The speed reference you have in your funct Player_Stats(speed) is a local variable. That is, it's not the same variable you created at the top of your DataImport.gd script. Because of that, your not actually setting the singleton's speed var in that function.

Try this instead:

func Player_Stats(new_speed):
    speed = new_speed
by (13,156 points)
edited by

Additionally, if the var you're trying to update is stored in a singleton, why not just update it directly (from wherever) rather than updating it via a signal? Maybe you have a valid reason, but it's something to think about...

It works, thank you for you help.

I am using signals because I try to control the speed from outside the main tree through instanced scene, but this is my first Godot project so I am sure there are many ways to do things more efficient.

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 webmaster@godotengine.org with your username.