Hello there!
First of all, sorry for this vague title, but making a proper title might take quite a lot of space, and second, this might be a little hard to explain and understand, so please, ask whatever you may need.
Summarizing, my problem is that I have a switch statement with two cases with no code and one with code, and when any of those two cases happen, the code from the other case that HAS code, triggers. And the second problem is that the code that triggers is actually wrong because its calling an event of the object obj_ts_close that doesn't have, but still triggers and 'works' as intended.
Well, first of everything, I will explain what I am trying to accomplish:
I have a simple title screen system with three posible selectable options:
- New game
- Options
- Close
At the moment, the "New game" and "Options" option, should not be doing nothing because I haven't coded anyting for them yet, but when the "Close" option is selected, and the user press ENTER, a window is drawn asking for confirmation to close the game, or to press ESCAPE to close that window. The problem is, even when "New game" and "Options" don't have anything coded, when I press ENTER when in any of those two options, the "Close" events trigger, and I am not sure why, because I have a problem with my switch statement, and is that as I said both options don't have anything coded but "Close" does, and the "Close" otpion is calling an event_perform_object() of an event that doesn't exist in that object, yet it works as intended with the excption that it also triggers in "New game" and "Options" option, and it shouldn't.
So my problem is: Why is this happening (the switch statement problem), and even if its 'working', why is it working if my code is wrong?
Here is all the code of each object:
obj_ts_menu (the main object of the system is coded here):
obj_ts_close (the object which the code of what the close option needs to do):
And a gif of the problem replicated.
Sorry for any trouble these explanations may cause, I find a little hard to explain without a proper visual explanation.
First of all, sorry for this vague title, but making a proper title might take quite a lot of space, and second, this might be a little hard to explain and understand, so please, ask whatever you may need.
Summarizing, my problem is that I have a switch statement with two cases with no code and one with code, and when any of those two cases happen, the code from the other case that HAS code, triggers. And the second problem is that the code that triggers is actually wrong because its calling an event of the object obj_ts_close that doesn't have, but still triggers and 'works' as intended.
Well, first of everything, I will explain what I am trying to accomplish:
I have a simple title screen system with three posible selectable options:
- New game
- Options
- Close
At the moment, the "New game" and "Options" option, should not be doing nothing because I haven't coded anyting for them yet, but when the "Close" option is selected, and the user press ENTER, a window is drawn asking for confirmation to close the game, or to press ESCAPE to close that window. The problem is, even when "New game" and "Options" don't have anything coded, when I press ENTER when in any of those two options, the "Close" events trigger, and I am not sure why, because I have a problem with my switch statement, and is that as I said both options don't have anything coded but "Close" does, and the "Close" otpion is calling an event_perform_object() of an event that doesn't exist in that object, yet it works as intended with the excption that it also triggers in "New game" and "Options" option, and it shouldn't.
So my problem is: Why is this happening (the switch statement problem), and even if its 'working', why is it working if my code is wrong?
Here is all the code of each object:
obj_ts_menu (the main object of the system is coded here):
GML:
/// CREATE EVENT
window_prompted = false;
current_select = "newgame";
GML:
/// STEP EVENT
switch ( current_select ) {
case "newgame":
inst_ts_newgame.image_index = 1;
inst_ts_options.image_index = 0;
inst_ts_close.image_index = 0;
break;
case "options":
inst_ts_newgame.image_index = 0;
inst_ts_options.image_index = 1;
inst_ts_close.image_index = 0;
break;
case "close":
inst_ts_newgame.image_index = 0;
inst_ts_options.image_index = 0;
inst_ts_close.image_index = 1;
break;
}
GML:
/// KEY UP - ENTER EVENT
switch ( current_select ) {
case "newgame":
break;
case "options":
break;
case "close":
event_perform_object( obj_ts_close, ev_keyrelease, vk_enter );
break;
}
GML:
/// KEY UP - UP EVENT
if ( !window_prompted ) {
switch ( current_select ) {
case "newgame":
current_select = "close";
break;
case "options":
current_select = "newgame";
break;
case "close":
current_select = "options";
break;
}
}
GML:
/// KEY UP - DOWN EVENT
if ( !window_prompted ) {
switch ( current_select ) {
case "newgame":
current_select = "options";
break;
case "options":
current_select = "close";
break;
case "close":
current_select = "newgame";
break;
}
}
GML:
/// CREATE EVENT
image_speed = 0;
confirmation_prompted = false;
GML:
/// @description
draw_self();
if ( confirmation_prompted ) {
draw_sprite_ext( spr_ts_confirm_exit, 0, room_width / 2 - 192, room_height / 2 - 168, 2, 2, 0, c_white, 1 );
if ( keyboard_check_pressed( vk_enter ) ) {
game_end();
} else if ( keyboard_check_pressed( vk_escape ) ) {
inst_ts_menu.window_prompted = false;
confirmation_prompted = false;
}
}
if ( !confirmation_prompted && keyboard_check_pressed( vk_enter ) ) {
inst_ts_menu.window_prompted = true;
confirmation_prompted = true;
}
Sorry for any trouble these explanations may cause, I find a little hard to explain without a proper visual explanation.