• 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!

Legacy GM Run through optional var values

T

TheRBZ

Guest
I have a simple button object set up that controls buttons. Some are simple, just go to a room.
Some are like options and need to run through a set of options
(e.g. Start on normal, go to hard, then go to easy then to normal, and cycle).

My current code is bulky and I'm sure there is a more efficient way.
Code:
switch(action)
{
//Speedrun button
    case 0:
        room_goto(rm_speedrun);
        break;
//Versus button         
    case 1:
        room_goto(rm_versus_set);
        break; 
//Disinfect Button       
    case 2:
        room_goto(rm_disinfect_set);
        break; 
//Disinfect mode button             
    case 3:
        if inst_10C4A282.text = "Normal"{
        inst_10C4A282.text = "Experimental"
        global.dis_mode = "experi";}
        else{
        inst_10C4A282.text = "Normal"
        global.dis_mode = "normal";}
        break; 
//Disinfect difficulty button           
    case 4:
        if inst_6CEA83E2.text = "Normal"{
        inst_6CEA83E2.text = "Hard"
        global.dis_dif = 999}
        else if inst_6CEA83E2.text = "Hard"{
        inst_6CEA83E2.text = "Easy"
        global.dis_dif = 5499}
        else if inst_6CEA83E2.text = "Easy"{
        inst_6CEA83E2.text = "Normal"
        global.dis_dif = 3499}
        break; 
//Versus mode button                 
    case 5:
    
        break;
//Versus time button               
    case 6:
    
        break;                         
}
In each instance creation code, it has this template:
Code:
text = "[first shown text]";
action = [action #];
It basically determines which piece of code is assigned to which instance.

If you look at case 3 and 4, you see my attempt at making a run through multiple options.
IS there a more efficient way of doing it?

Also, if you need to see more code with the objects and instances, just say.
 

Simon Gust

Member
It's pretty good. But did you know you can also check strings in a switch statement
Code:
case 4:
switch (inst_6CEA83E2.text)
{
  case "Normal":
    inst_6CEA83E2.text = "Hard";
    global.dis_dif = 999;
    break;
  case "Hard":  
    inst_6CEA83E2.text = "Easy";
    global.dis_dif = 5499;
    break;
  case "Easy":
    inst_6CEA83E2.text = "Normal";
    global.dis_dif = 3499;
    break;
}
 
T

TheRBZ

Guest
Oh, come on! I knew there was something like that. Thanks for saving my life again.
Yes, I know I already know that method.
 
Top