I know that my question is probably very stupid, but I can't figure out what the problem is. (maybe there is no problem. and I just don't have enough knowledge)
The project tree is very simple:
- - KinematicBody2D
- - - CollisionShape2D
- - - Sprite
- - - - Panel
- - - - - Label
In the KinematicBody2D node, a script with simple control and variable speed.
var speed = 70
var velocity = Vector2()
velocity.y -= speed
velocity.y += speed
get_node("Sprite").flip_h = true
velocity.x -= speed
get_node("Sprite").flip_h = false
velocity.x += speed
speed = 120
speed = 70
position.x = clamp(position.x, 5, 335)
position.y = clamp(position.y, 0, 330)
In the Label node, a simple script that should show the value of the speed variable from the script in KinematicBody2D.
And here lies my problem.
If I try to access the KinematicBody2D node to get the value of a variable velocity in $KinematicBody2D.speed (auto-complete, and there have to print the manual), when you run the project I receive an error "Invalid get index 'speed' (on base: 'null instace')"
If you are applying through get_node(), then the autocomplete suggests ".", what's not working.
The only working way I could find:
text = "speed: " + String(get_parent().get_parent().get_node("KinematicBody2D").speed)
It seems to me that I am missing some simple way to indicate the path to another node.
Or is that exactly how it should work?