0 votes
#FSM States
enum {BEAM, APPEAR, IDLE, LILSTEP, RUN, JUMP, SLIDE, CLIMB, CLIMB_TOP, HURT, FALL, DEAD, LEAVE}

func change_state(new_state):
    state = new_state
    match state:
        BEAM:
            new_anim = 'beam'

Getting an "Expected end of statement after expression" error on the line containing 'match' when porting my game from 3.1 alpha to 2.1.5.

Is there an equivalent for the above function so I can continue to use a finite state machine?

in Engine by (197 points)

Seems I need to chain a bunch of IF statements for this to work. MATCH is a 3.0 addition.

Hi, you are correct... in Godot 2 you must use if .. elif .. else .. like in python. There are other questions in this forum that states the same. Please, can you post your finding as an answer and mark it as best? so question does not remains unanswered.

If you don't want to use tons of elifs, you could also use Dics. At least if it's something akin to your example. At least if you as many states as you describe.

1 Answer

0 votes
Best answer

As i answered in another question:

if case == 0:
    pass
elif case == 1:
    pass
else:
    pass

Something like that

by (3,400 points)
selected by
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 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 webmaster@godotengine.org with your username.