Change variable from parent class.

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

Hello everyone. I have two scripts, one of them defines a Character class and other extends the Character class and provides the code for the player. However, the Character script holds the movement variables for the player and I don’t want to change this.

How can I call the variable from the character script and modify it in the player script?

:bust_in_silhouette: Reply From: godot_dev_

suppose you have the below two class definitions

#Character class
var parentVar=0
func _ready():
   ...

#Player class (extends Character class)
var childVar=0
func _ready():
   parentVar=1 #we modifier the parent scripts 'parentVar' member, even if the variable isn't defined in the player class script
   childVar=1 #we modify our child class's member

Above illustrates (in the _ready function of the Player class) how we can access a member (parentVar) of the parent script from inside the child class.

Does this help?