accessing member variables from inner classes

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

So I have this character system which is based on fsm concept, states are inner classes where each state has its own behaviour.
Accessing member variables and comparing them works in some instances and doesn’t works in others, even though the code is the same.

Here is a code example:

#---------- STRUCK --------------
class Struck:
	var player
	
	func _init(player):
		self.player = player
		player.get_node("Animation").play("STRUCK")
	
	func update(delta):
		var struck_anim = player.get_node("Animation")

		# Below is where the error happens
		if struck_anim.current_animation_positon == struck_anim.current_animation_length:
			player.set_state(IDLE)
	
	func input(event):
		pass
	
	func exit():
		pass

This throws me the following error as soon as I trigger this subclass:

Invalid get index 'current_animation_positon' (on base: 'AnimationPlayer').

For some reason, this works flawlessly with other inner classes. Here is an example that works:

#---------- SHOOT --------------
class Shoot:
	var player
	
	func _init(player):
		self.player = player
		player.get_node("Animation").play("SHOOT")
	
	func update(delta):
		var shoot_anim = player.get_node("Animation")
		
		if shoot_anim.current_animation_position == shoot_anim.current_animation_length:
			player.set_state(IDLE)
	
	func input(event):
		pass
	
	func exit():
		pass

Hopefully someone knows what is going on here.

:bust_in_silhouette: Reply From: hilfazer

A typo:
current_animation_positon
missing ‘i’.

thats embarrasing. thank you for finding it. drove me nuts.

nooberdev | 2018-08-16 16:51