Keyboard Check Pressed Moves through 2 Objects on Vk_Left

N

Naeem Sanders

Guest
Hello all, very new to game maker studio.

I have an Action Select Obj that I want the player to be able to cycle through, I have a step event that where I check if the keyboard_check_pressed is vk_left then hide the first object and show the second. The problem is when I add a step event that checks for another keyboard_check_pressed(vk_left) it doesn't stop at the object and just moves through on one left click. Is there a way to make it so that when I click left on one object it moves to the next then waits for another left click to move to the next?

Thank you so much in advance!

Here's my code so far:
//This hides the first object on left arrow click and makes the next object visible
if keyboard_check_pressed(vk_left){
if (Action_Sel_Atck_Obj_1.visible = true) {
visible = false;
Action_Sel_Spec_Obj.visible = true;
}
}
else {
return
}

// When I add this to the Action_Sel_Spec_Obj it does not stop and just moves to the next object

if keyboard_check_pressed(vk_left){
if (Action_Sel_Spec_Obj.visible = true) {
visible = false;
Action_Sel_Esc_Obj.visible = true;
}
}
else {
return
}
 

CloseRange

Member
My suggestion is get some object that is always in the room that there is only 1 of (this could be some controller object or the player object or a ui object or something like that)
in the create event:
Code:
// the currently selected object, leave at 0
global.action_select = 0;
// how many action_select objects you have in total, increase it as you add more
max_action_selects = 2;
and in the step event for the same object:

Code:
// if you press the left key, increase the selected object by 1
if(keyboard_check_pressed(vk_left)
     global.action_select++;
// if you press the right key, decrease the selected object by 1 (only if you want the right key to go the other way)
if(keyboard_check_pressed(vk_right)
     global.action_select--;
// this will allow it to cycle through all of the objects
if(global.action_select < 0)
     global.action_select = max_action_selects -1;
if(global.action_select >= max_action_selects)
     global.action_select = 0;
ok now for each action select object give it a unique id called my_action_select:

Code:
/// Action_Sel_Atck_Obj
my_action_select = 0;
/// Action_Sel_Atck_Obj_1
my_action_select = 1;
and in their step event:
Code:
// only visible if the current action select is me
visible = (global.action_select == my_action_select);
 
N

Naeem Sanders

Guest
My suggestion is get some object that is always in the room that there is only 1 of (this could be some controller object or the player object or a ui object or something like that)
in the create event:
Code:
// the currently selected object, leave at 0
global.action_select = 0;
// how many action_select objects you have in total, increase it as you add more
max_action_selects = 2;
and in the step event for the same object:

Code:
// if you press the left key, increase the selected object by 1
if(keyboard_check_pressed(vk_left)
     global.action_select++;
// if you press the right key, decrease the selected object by 1 (only if you want the right key to go the other way)
if(keyboard_check_pressed(vk_right)
     global.action_select--;
// this will allow it to cycle through all of the objects
if(global.action_select < 0)
     global.action_select = max_action_selects -1;
if(global.action_select >= max_action_selects)
     global.action_select = 0;
ok now for each action select object give it a unique id called my_action_select:

Code:
/// Action_Sel_Atck_Obj
my_action_select = 0;
/// Action_Sel_Atck_Obj_1
my_action_select = 1;
and in their step event:
Code:
// only visible if the current action select is me
visible = (global.action_select == my_action_select);

Thank you so much for the help, your code helped out a lot! Many thanks again!
 
Top