The obscure art of makin' a menu
(Previously posted on GCUK forums - www.gamecoding.co.uk/forums)
This one another of my problems that''ve been bugging me off for the last weeks:
while(1){
if(key[KEY_UP] && (p > 0)){
poll_keyboard();
p--;
}
if(key[KEY_DOWN] && (p < 2)){
poll_keyboard();
p++;
}
if(key[KEY_ENTER]){
switch(p){
case 0: // New Game
// caca
break;
case 1: // Credits
// caca
break;
case 2: // Exit
// caca
break;
}
}
}
So? Yep. That menu won''t work. I mean the keyboard reads, but the last if-statement don''t work. Normally the while()-sling should exit, but nothing happens. Help?
//toki
I think the breaks you put in that switch-thingy just break out of the switch loop, not the while loop. You could build the while loop like this:
Then in the switch statement you could set bDone to true, and the while loop would end.
-----------------------------
Jappie
BabJap Productions
"There''s no such things as bugs; they''re just unintentional extra features"
while( !bDone ){}
Then in the switch statement you could set bDone to true, and the while loop would end.
-----------------------------
Jappie
BabJap Productions
"There''s no such things as bugs; they''re just unintentional extra features"
Or you could have
continue;
break;
instead of just break; inside the switch
----------------
Freeride Designs
----------------
continue;
break;
instead of just break; inside the switch
----------------
Freeride Designs
----------------
quote:Original post by Freeride Designs
Or you could have
continue;
break;
That break would never execute, since as soon as the continue is reached, you jump to the conditional in the while. The loop would still be infinite.
Jappie has a good solution.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement