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

[SOLVED] Need help at switch statement: Wont work

G

Grammar

Guest
Hey there guys,

today I have a cool error, I made a Switch-Case Statement in a Script for choosing the Enemy, but every time, I get the last case (case 2: ). So, if my Variable for the Switch Statement is 0,1,3,4,5... I will get the Case 2 for sure. I was print te Variable with draw_text(), and its not 2 at this Section. Here is my Code:


Code:
search_he[0]=argument0
search_he[1]=argument1
search_he[2]=argument2
search_he[3]=argument3
search_he[4]=argument4
search_he[5]=argument5
search_he[6]=argument6
search_he[7]=argument7
search_he[8]=argument8
search_he[9]=argument9


//Gegner Auswahl gespeichert in global.enemvali[]

for (i=0; i<10; i+=1) {

switch search_he[i]{


case 1:

global.enem_vali[i,0]=1
global.enem_vali[i,1]=12
global.enem_vali[i,2]=20
global.enem_vali[i,3]=310
global.enem_vali[i,4]=3
global.enem_vali[i,5]=1
global.enem_vali[i,6]=4
global.enem_vali[i,7]=0
global.enem_vali[i,8]=0
global.enem_vali[i,9]=0
global.enem_vali[i,10]=1
global.enem_vali[i,11]=8    //Gold
global.enem_vali[i,12]=4    //Dia Chance
global.enem_vali[i,15]=14

case 2:

global.enem_vali[i,0]=1
global.enem_vali[i,1]=12
global.enem_vali[i,2]=20
global.enem_vali[i,3]=300
global.enem_vali[i,4]=3
global.enem_vali[i,5]=1
global.enem_vali[i,6]=4
global.enem_vali[i,7]=0
global.enem_vali[i,8]=0
global.enem_vali[i,9]=0
global.enem_vali[i,10]=1
global.enem_vali[i,11]=8
global.enem_vali[i,12]=4
global.enem_vali[i,15]=14

}
}

The funny thing is I have the same problem for my Item-System. Something like the same script, but with more Case-Functions and Action's. But it dont matter, if my item-switch Variable is 1,2,3... every time the last Case (Case 5: ) will be called.

Someone know how to fix this? Maybe its a stupid Error, I am sorry if it is, but I programmed for day's on this game and my brain is mud know.

Thank you guys!

- Cheers TaPS
 

NeoShade

Member
Try adding a break; at the end of each case to make sure it doesn't flow on into the next case.

Code:
break;
 
G

Grammar

Guest
Oh dayum, thanks for that mate, it work know in both scripts. So at the end it was a silly error ^^

- Cheers, TaPS
 
Top