• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Legacy GM [Solved] State machine executes every script.

G

Gunslito

Guest
Hello guys, I'm new here, this is not my native language so excuse me if I mess up with some words

I've a really annoying problem, when I try to use a state machine it executes every script of every case, even if the variable is different.

enum states{stand,walk,transition,fly,flap,attack,swim,death}

state=states.stand

enum configs{normal,death}

gconfig=configs.normal

switch(gconfig)
{
case configs.normal:
{
scr_inputs();scr_movement();scr_collision();scr_animations();
switch(state)
{
case states.stand: scr_stand();break;
case states.walk: scr_walk();break;
case states.transition: scr_transition();break;
case states.fly: scr_fly();break;
case states.flap: scr_flap();break;
case states.attack: scr_attack();break;
case states.swim: scr_swim();break;
}

}
case configs.death: scr_movement();scr_collision();scr_animations();
switch (state)
{
case states.death: scr_death(); break
}
}​

The thing is that as you can see if for example, the var "State" is equal to "stand" all cases will execute no matter what,
the var gconfig is configs.normal but the scripts "scr_movement, scr_collision and scr_animations executes 2 times because they're on gconfig=configs.death too, why is this happening?
I'm so sorry for bothering you with this question, thanks in advance for your help!
 
G

Gunslito

Guest
Yeah, if I do that the animations breaks, it'll be better to take out that script and make it run on step individually right? Thank you Yellow!

Edit: What I ended doing is putting the "Break;" statement and the end of each "gconfig" case, because I was trying to put it on here:
switch(gconfig)
{
case configs.normal:
{
scr_inputs();scr_movement();scr_collision();scr_animations();
switch(state) break; <----------
{
case states.stand: scr_stand();break;
case states.walk: scr_walk();break;
case states.transition: scr_transition();break;
case states.fly: scr_fly();break;
case states.flap: scr_flap();break;
case states.attack: scr_attack();break;
case states.swim: scr_swim();break;
}
}
when it goes here:
switch(gconfig)
{
case configs.normal:
{
scr_inputs();scr_movement();scr_collision();scr_animations();
switch(state)
{
case states.stand: scr_stand();break;
case states.walk: scr_walk();break;
case states.transition: scr_transition();break;
case states.fly: scr_fly();break;
case states.flap: scr_flap();break;
case states.attack: scr_attack();break;
case states.swim: scr_swim();break;
break; <----------
}
}

thank you for helping me realize that! I'll edit title :)
 
Last edited by a moderator:
Top