Topic was automatically imported from the old Question2Answer platform.
Asked By
The_Black_Chess_King
Doing FSM and sometimes you want the same logic to be applied for multiple states, for instance, aiming a weapon should be allowed when the player is idle, walking or running.
For such common situation normally I would do, as you guessed:
#AIM WEAPON - logic
func Something_Foobar() -> void:
if STATE == "IDLE" or STATE == "WALK" or STATE == "RUN": pass
# Allow aim weapon code check.
# Allow firing weapon.
How I would go about on doing them like this: if STATE == ("IDLE" or "WALK" or "RUN"): or better even if STATE == ("IDLE","WALK","RUN"): or the inverse if ("IDLE" or "WALK" or "RUN") in STATE:
I would avoid using (arrays or dictionaries or for) loops just for this.
In addition to the array suggested by Wakatta, a second alternative would be using match, especially if you’ve got more than one group with specific code:
match STATE:
"IDLE", "WALK", "RUN":
# Code when standing on the ground
"JUMP", "FALL":
# Code when in the air
"SWIM", "FLOAT":
# Code when in a liquid