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

Windows Switch statement not working.

Hello community! I have an inquiry regarding how complicated code can get until GameMaker passes on a code the wrong way or fails completely. I have a long sample of code (abridged herein for surveying purposes) that has multiple if and multiple switch statements in an array in which every one of them is inside the brackets ( { } ) of another. The array has up to 4- or 5-ish layers of this in a few of the objects' events.

Now, the issue is that even though I have a case clearly defined and clearly broken with the "break;" commands on the right places before the appropriate brackets, one case seems to override the other. Where the code comments describe the Placeholder and Grammar Modes, it should label 1 as the Placeholder case for the Questions Mode and 2 for Grammar. Can anybody help me out with this or with finding a better way of writing code at all?

Code samples:

Objt_Choice A \ Create Event \

vSelected = 0; TouchingGamePad = 0;



Obj_Choice A \ Left-Pressed Event \

//It becomes selected in pontentiality.

vSelected = 1;



*This event especially has an abridged version herein of the longer set of similarly structured sections of code by category, by level/question, and by the Questions Mode. It almost repeats the exact format of code sequences with exceptions of nitty-gritty things like the values.*

Objt_Choice A \ Step Event \

if(vSelected==1){

switch(global.QuestionsMode){

//Case 1 is the Placeholder Case.

case 1:

//The beginning of checking for the CategoryA room.

if(room==rm_CategoryA){

//This condition below regards the question from category A, 100 points.

if(global.jquestion=="Answer A0"){

//Answer A0 is right.

//Level 100A would stop existing if the player got it right.

global.lOneA_exist=0;

//100 points times the level number without the two zeros attached adds to the respective team's score.

//But first, it has to check the current team having made the choice.

switch(global.CurrentTeam){

case 1:

global.TeamAScore+=(100*global.vLevelSelect);

//Finally, it goes to the room for being correct.

room_goto(rm_CorrectAns); break;

case 2:

global.TeamBScore+=(100*global.vLevelSelect);

//Finally, it goes to the room for being correct.

room_goto(rm_CorrectAns); break;

}

}

}

}

}
 

TheouAegis

Member
All i see is code for assigning points to TeamA or TeamB. I don't see anything that is wrong with what you posted
 

chamaeleon

Member
I don't see a single debug statement before any conditional or switch that would tell you why a particular code path is or is not taken. Why not?
 
And yet, somehow, when I click the Choice A Object (objt_Choice A) in the game's run--thus triggering the Left-Pressed event--the parts in the Step Event in which the vSelected and global.QuestionsMode variables don't go through with their triggers. I speak of the triggers for the behalf of the Grammar Case as well as for that of the "selected value" (1) for vSelected. Something does not make sense in the code. Why is it doing that unfair override? Can I show this thread some video proof?
 

chamaeleon

Member
And yet, somehow, when I click the Choice A Object (objt_Choice A) in the game's run--thus triggering the Left-Pressed event--the parts in the Step Event in which the vSelected and global.QuestionsMode variables don't go through with their triggers. I speak of the triggers for the behalf of the Grammar Case as well as for that of the "selected value" (1) for vSelected. Something does not make sense in the code. Why is it doing that unfair override? Can I show this thread some video proof?
Instrumented code with a lot of show_debug_message output before, inside, and after all if and switch blocks would be vastly preferred, I would imagine. A meaningful message plus the values used in each conditional.
 
Okay... I actually got myself into an embarrassing situation. You guys were awesome for at least confirming that I had the code right... But then I realized something on my error. I already quintuple-checked objt_game, objt_Choice A, and some other objects as well. However, I accidentally skipped over a part in the category-by-category code in the Room Start event for objt_questions... MISSING BREAK STATEMENTS!

Sorry to give you guys a big request over a small fix. Thanks for the help, though.
 
Top