I have a menu system with different states. One of the states is activated by an external event -- oComputer -- that then passes the following values on to the oPauseMenu event:
oPauseMenu's main state is unpaused, which happens when you press "Escape" to get out of the menu. This changes the state to the small computer menu displaying.
oPauseMenu.savedelay is a timer that stops from automatically activating the "No" option and closing out of the menu in the same step that you open the menu. It counts down to 0 as soon as the oPauseMenu is opened.
oPauseMenu.subpointer just shows which option you're selecting. It defaults to 1.
The problem is within the code in the oPauseMenu object, specfically in pausestate.computeruse, and specifically in the bolded section below (NOTE: search for the [.B] and [/.B] :
When this state runs, and subpointer = 1, I should only have to press key_use ONCE to close the menu.
When this state runs, I should only have to press key_use ONCE to close the menu. However, I in fact have to press it TWICE. On the first press, the screensave screenshot is deleted, but none of the events are reactivated. Also, the "Reset the room?" text, box, pointers, etc. still work. I can even move the pointer over to "Yes" and reset the room. If I want to close the menu, I have to press "No" again. Then I finally get the result I'd been looking for.
What's strange is that I SEE the above code change pausemenustate to unpaused, and then immediately after, it's changed back. When I press "Use" again, the same code runs again, but I get a different result. Nowhere else in the game is pausemenustate set to pausemenustate = pausestate.computeruse changed in the game... so why would it be changed IMMEDIATELY back to it after supposedly changing states?
edit: if I remove the "&& savedelay < 1" the code runs correctly, EXCEPT THAT the menu closes IMMEDIATELY as soon as it opens, which is obviously undesirable. So the timer I'm using to *not* break the code is what breaks it in a different and inexplicable way.
GML:
{oPauseMenu.savedelay = 1; oPauseMenu.subpointer = 1; oPauseMenu.pausemenustate = pausestate.computeruse} // Asks the question and runs the variables
oPauseMenu.savedelay is a timer that stops from automatically activating the "No" option and closing out of the menu in the same step that you open the menu. It counts down to 0 as soon as the oPauseMenu is opened.
oPauseMenu.subpointer just shows which option you're selecting. It defaults to 1.
The problem is within the code in the oPauseMenu object, specfically in pausestate.computeruse, and specifically in the bolded section below (NOTE: search for the [.B] and [/.B] :
GML:
#region Computer Menu
case pausestate.computeruse:
pause = 1;
if screensave == 0
{screensave = sprite_create_from_surface(application_surface,0,0,surface_get_width(application_surface),surface_get_height(application_surface),0,1,0,0);}
instance_deactivate_all(true);
var _compboxX = display_get_gui_width()/2; // Where to start drawing text
var _compboxY = display_get_gui_height()/5; // Where to start drawing text
var _compboxXscale = ((_compboxX * 0.25) + (_compboxX * 1.25)) / xscaleL / 32 // Refers to the width in pixels of the sprite being drawn
var _compboxYscale = ((_compboxY * 1.25) + (_compboxY * 1.50)) / yscaleL / 32
var _compfontsize = 29 * xscaleN // For making window symmetrical even with ">" drawn in front of "Yes"
// Places pointer in correct spot if game is translated
var _fa_nocompbox_pointer = string_length(DisplayText("9")) * 29 * xscaleL // 29 = size of each letter at scale of 1
// Draws the box
{draw_sprite_ext(windowsprite,0,(_compboxX),(_compboxY*1.5),_compboxXscale,_compboxYscale,0,c_white,1)}
{draw_sprite_ext(spr_gui_tabs_vex,0,(_compboxX*1.31),(_compboxY*0.72),xscaleN,xscaleN,0,c_white,1)}
draw_set_halign(fa_center)
draw_text_transformed(_compboxX, _compboxY, DisplayText("104"), xscaleL,yscaleL, 0); // Reset the room?
draw_set_halign(fa_left)
draw_text_transformed(_compboxX*0.75+_compfontsize, _compboxY*1.5, DisplayText("8"), xscaleL,yscaleL, 0); // Yes
draw_set_halign(fa_right)
draw_text_transformed(_compboxX*1.25, _compboxY*1.5, DisplayText("9"), xscaleL,yscaleL, 0); // No
if key_left {subpointer--;}
else if key_right {subpointer++;}
subpointer = clamp(subpointer,0,1)
if (subpointer = 0)
{
draw_set_halign(fa_left)
if key_use && savedelay < 1 // Resets room variables; savedelay is important as a timer
{
instance_activate_all();
pause = 0;
screensave = 0;
subpointer = 0;
scr_compreset();
}
draw_text_transformed(_compboxX*0.70+_compfontsize, _compboxY*1.5, ">", xscaleL,yscaleL, 0);
}
else if (subpointer = 1)
{
[B] if key_use && savedelay < 1
{
instance_activate_all();
pausemenustate = pausestate.unpaused;
screensave = 0;
pause = 0;
savedelay = 0;
subpointer = 0;
}[/B]
draw_text_transformed(_compboxX*1.25 - _fa_nocompbox_pointer, _compboxY*1.5, ">", xscaleL,yscaleL, 0);
}
savedelay--; // Just used as a timer so that this menu biz doesn't activate automatically when you use the computer
break;
#endregion
When this state runs, I should only have to press key_use ONCE to close the menu. However, I in fact have to press it TWICE. On the first press, the screensave screenshot is deleted, but none of the events are reactivated. Also, the "Reset the room?" text, box, pointers, etc. still work. I can even move the pointer over to "Yes" and reset the room. If I want to close the menu, I have to press "No" again. Then I finally get the result I'd been looking for.
What's strange is that I SEE the above code change pausemenustate to unpaused, and then immediately after, it's changed back. When I press "Use" again, the same code runs again, but I get a different result. Nowhere else in the game is pausemenustate set to pausemenustate = pausestate.computeruse changed in the game... so why would it be changed IMMEDIATELY back to it after supposedly changing states?
edit: if I remove the "&& savedelay < 1" the code runs correctly, EXCEPT THAT the menu closes IMMEDIATELY as soon as it opens, which is obviously undesirable. So the timer I'm using to *not* break the code is what breaks it in a different and inexplicable way.
Last edited: