Can I modify the WALK_MAX_SPEED variable directly from the inheriting script
Yeah, you can do whatever you want with this variable in extending scripts, including what you’ve done in _ready() callback. But you can’t re-declare the same variable inside extended script though.
You might want to look at overriding _init() method to reinitialize the variable on creation:
func _init(max_speed):
WALK_MAX_SPEED = max_speed
var character = Character.new(200)
If for some reason you want to restrict the access to the variable from outside the script, you declare your variable as:
var WALK_MAX_SPEED = 120 setget set_max_walk_speed, get_max_walk_speed
func set_max_walk_speed(p_speed):
# You can encapsulate how you would want to set maximum speed internally
WALK_MAX_SPEED = max(0, p_speed)
func get_max_walk_speed():
return WALK_MAX_SPEED
So when you access WALK_MAX_SPEED from outside the script like:
character.WALK_MAX_SPEED = 200
What it will do is actually call set_max_walk_speed() method to set speed. Take in mind that these set/get will only get triggered from outside the script, you’ll need to use actual methods inside the script then.