This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

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.

in Engine by (143 points)

1 Answer

+1 vote
Best answer

A typo:
currentanimationpositon
missing 'i'.

by (2,308 points)
selected by

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.