GDScript: How to call methods with slash in their names?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By wombatstampede

I want to set a member variable of HingeJoint:

The docs say that the name is “float motor/target_velocity”.

But I find no way accessing it. I tried $MyJoint.motor/target_velocity or $MyJoint."motor/target_velocity" or $MyJoint.motor_target_velocity.

It just raises errors.
I can use the set_param method though: $MyJoint.get_param(HingeJoint.PARAM_MOTOR_TARGET_VELOCITY)

But it would make no sense when the docs states member variables that are not accessible.

So: How do I access member variables with “/” in the identifier?

:bust_in_silhouette: Reply From: hilfazer

This is my best try:


It’s also the only thing that worked for me.

Thank you hilfazer,
your method seems the best way to access objects properties with “odd” naming.

wombatstampede | 2019-02-04 07:38

:bust_in_silhouette: Reply From: Dlean Jeans

Shorter alternative:

# get
var target_velocity = $HingeJoint['motor/target_velocity']

# set
$HingeJoint['motor/target_velocity'] = value