Feet loving incomprehencable "str_to_var" function help

Godot Version

4.6

Question

Hey! trying to change the speed of footsteps based on the player state but i can’t seem to do the things i want, it’s probably just a me problem but i’d apreciate some help!:

## in player script

	# change stuff based on state
	if prev_state != state:
		if state == States.falling:
			acceleration_speed = 2.0
			
		else:
			acceleration_speed = 9.0
			
			if state == States.walking: # walking
				target_speed = WALK_SPEED
				feet.change_fs_state("walking")
				
			elif state == States.sprinting: # sprinting
				target_speed = SPRINT_SPEED
				feet.change_fs_state("sprinting")
			
			if state == States.crouching: # crouching
				feet.change_fs_state("crouching")
				target_speed = CROUCH_SPEED
				crouching_colision.disabled = false
				standing_collision.disabled = true
			else:
				crouching_colision.disabled = true
				standing_collision.disabled = false
		
		# check if landing and call land function
		if (prev_state == States.falling):
			land()
	
## in foot script

var walking_speed = 0.4
var crouching_speed = 0.4
var sprinting_speed = 0.4


func change_fs_state(state : String):
	if state != null:
		fs_timer.wait_time = str_to_var(state+"_speed")

Im sending the state of the player to the feet as a string so that i can use the str to var function but i guess i didn’t know how the str to var function works. I think it’s just using the type of the “state” variable in the foot function to convert to and i dont really know hot to fix this, thanks for any help!

Check the documentation of str_to_var() function, it has an example that should make it clearer.

What you need in your case is just Object::get().

## in foot script

var walking_speed = 0.4
var crouching_speed = 0.4
var sprinting_speed = 0.4


func change_fs_state(state : String):
	if state != null:
		fs_timer.wait_time = get(state+"_speed")
1 Like