0 votes

I am attempting to use a Timer to change a variable within the Timer's parent node upon timeout.

func onDashTimertimeout():
get
node("root/Game/Level1/Player").ACCELERATION = 10
get
node("root/Game/Level1/Player").MAXSPEED = 50
getnode("root/Game/Level1/Player").velocity = getnode("root/Game/Level1/Player").current_velocity

However, when I try to run it, it comes up with the error "Invalid set index 'ACCELERATION' (on base: null instance) with value of type 'int'"

Anyone know how to fix this?

Godot version 3.5.1
in Engine by (14 points)

2 Answers

0 votes

Hello,
A slight educated guess. The get node command isn't finding your Player node.

Put a print statement and if it's null then that's what it is:

print (get_node("root/Game/Level1/Player"))

What I do is use a Global script to set the player node in the player ready function:

Global.player = self

then you can access the variables in you timer function like this:

Global.player.ACCELERATION = 10

You will have to make sure the player node sets its node value before accessing it with other scripts. Either spawn your player first or check that Global.player is set.

by (2,047 points)
0 votes

If you're trying to change a variable within the timer's parent, you can do it without accessing the absolute path to the node; Assuming the timer's parent is the player object itself, the function could be written as:

func _on_DashTimer_timeout():
    ACCELERATION = 10
    MAXSPEED = 50
    velocity = current_velocity
by (1,305 points)
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.