0 votes

Hi All, new member here.
I'm trying to add a rpmmeter.tscn scene to a car scene.tscn
The car scene has a body with a script attached for the physics, and i am dragging in also the rpm
meter scene with a script.
In the rpm_meter script i want to call the rpm value to animate a 2d polygon.
I haven't succeded with direct call nor with a function like so:

rpm variable declared like so in car scene:
export var rpm = 0 setget, rpm_get
Function in car scene script:
func rpm_get():
return rpm

Function call in rpmmeter scene:
*print(get
node("car.tscn/body").rpm_get())*

in Engine by (12 points)

To format your code, write it, then select it all and click the "code sample" button. Alternatively, you can write it in another text editor, indent it all by one tab, then copy/paste it.

1 Answer

+1 vote

You're doing several things wrong here. You don't need a setget, and even if you did, you're not using it since you're trying to call the function instead of accessing the variable (which is what setget is for: calling a function when a variable is accessed).

It's hard to tell exactly what is happening because of your formatting issues in your post (_ character is for italics in text), but I think I see. You have an instance of a car scene that has another scene as a child, like so:

Car
  |-- RPM_meter

When you use get_node(), you use node names not filenames. car.tscn is a filename - it's where the scene is saved but has nothing to do with the node running in the live game. Since the car is the parent, you can use get_parent():

print(get_parent().rpm)

Keep in mind, this will not work if it's in the child's _ready() function, because child nodes become ready before parents.

Accessing nodes is frequently misunderstood by beginners. The following might help you avoid some of the common errors:

http://kidscancode.org/godot_recipes/basics/getting_nodes/

by (20,679 points)

Thanks a lot. Wasn't aware of the kidscancode resource. Will use it a lot. Will try to fix the problem right now (my lack of knowledge problem).
:)

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 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.