Jump to content


Photo

Move between Buttons with Arrow Keys


  • Please log in to reply
9 replies to this topic

#1 Devilfromhost12

Devilfromhost12

    GMC Member

  • GMC Member
  • 735 posts

Posted 27 May 2012 - 06:58 PM

I have these 3 "Buttons" that you can move between with the arrow keys. And when you press enter on the corresponding buttons you go to 3 different rooms depending on what button you are on. Well it is not working, and I was wondering if you guys had any like code ideas to do something like this.

-Thank you-

Edited by Chronic, 28 May 2012 - 02:05 AM.

  • 0

#2 Zoltan Kriven

Zoltan Kriven

    GMC Member

  • GMC Member
  • 340 posts
  • Version:GM8.1

Posted 27 May 2012 - 07:05 PM

I have these 3 "Buttons" that you can move between with the arrow keys. And when you press enter on the corresponding buttons you go to 3 different rooms depending on what button you are on. Well it is not working, and I was wondering if you guys had any like code ideas to do something like this. Here is the code I tried and when I pressed right it skipped the medium button, and it wouldn't go to the room I wanted it to when I pressed enter. So what is a good way to do this? Here is the code I used:

Keyboard Event for Key Enter:

execute code:

if place_meeting(48,224,obj_easy_difficulty)
{
room_goto(Survival_easy_room)
}

execute code:

if place_meeting(208,224,obj_medium_difficulty)
{
room_goto(Survival_room)
}

execute code:

if place_meeting(368,224,obj_hard_difficulty)
{
room_goto(Survival_hard_room)
}

Key Release Event for Key Left:

execute code:

if x=208
{
x=48
y=224
}


execute code:

if x=368
{
x=208
y=224
}


Key Release Event for Key Right:

execute code:

if x=48
{
x=208
y=224
}


execute code:

if x=208
{
x=368
y=224
}

That was copied out of the Show Information Button within the object. :)

-Thank you-


I would just make your buttons seperate objects, put a left mouse click event then just use the drag and drop to go to the designated room.
  • 0

#3 Jake Armstrong

Jake Armstrong

    GMC Member

  • GMC Member
  • 390 posts

Posted 27 May 2012 - 07:11 PM

Both code blocks are executed, so you need an else statement. Without one the x is changed to 208 which makes me the next part true, so x is changed again.
Also, changing the y is unnecessary if it never changes.

if x=48
{
x=208
}
else if x=208
{
x=368
}
  • 0

#4 Devilfromhost12

Devilfromhost12

    GMC Member

  • GMC Member
  • 735 posts

Posted 27 May 2012 - 07:53 PM

That worked Fantastically jake. But how would I make the enter work?
  • 0

#5 Jake Armstrong

Jake Armstrong

    GMC Member

  • GMC Member
  • 390 posts

Posted 27 May 2012 - 08:05 PM

Does it always go to the easy room? place_meeting(48,224,obj_easy_difficulty) would likely always be true as there is always an easy button near 48, 224
You are changing x, so you probably want:
if place_meeting(x,224,obj_easy_difficulty) {
room_goto(Survival_easy_room)
} else if place_meeting(x,224,obj_medium_difficulty) {
// etc.
  • 0

#6 Devilfromhost12

Devilfromhost12

    GMC Member

  • GMC Member
  • 735 posts

Posted 27 May 2012 - 08:12 PM

There are 3 different rooms, a easy, medium, and hard mode rooms. So would I do:

if place_meeting(48,224,obj_easy_difficulty)
{
room_goto(Survival_easy_room)
}
else if place_meeting(208,224,obj_medium_difficulty)
{
room_goto(Survival_medium_room)
}
else if place_meeting(368,224,obj_hard_difficulty)
{
room_goto(Survival_hard_room)
}
  • 0

#7 creators124

creators124

    awesomeliciousmember

  • GMC Member
  • 866 posts
  • Version:GM8

Posted 27 May 2012 - 08:23 PM

wouldn't it be easier to do a variable not object check?
like so:
//this goes in the step event
if (keyboard_check_pressed(vk_left)) //mostly to move between buttons, select = 0 is easy, select = 1 is medium, select = 2 is hard
{
    global.select -= 1;
}
else if (keyboard_check_pressed(vk_right))
{
    global.select += 1;
};

if (global.select < 0) //if you have gone to far bellow
{
    global.select = 2;
}
else if (global.select > 2) //or to high
{
    global.select = 0;
};
if (keyboard_check_pressed(vk_enter)) //when you press enter you'll go to it
    {
    if (global.select == 0) //checks to see if it is selecting the easy button
     {
        room_goto(easy_room_level); //please change the room name
     }
     else if (global.select == 1) //ect...
     {
              room_goto(medium_room_level);
}
else if (global.select == 2) //more ect...
{
        room_goto(hard_room_level);
}
}

Edited by creators124, 27 May 2012 - 09:52 PM.

  • 0

#8 Jake Armstrong

Jake Armstrong

    GMC Member

  • GMC Member
  • 390 posts

Posted 27 May 2012 - 08:35 PM

If you want to continue how you have it:

if place_meeting(x,224,obj_easy_difficulty)
{
room_goto(Survival_easy_room)
}
else if place_meeting(x,224,obj_medium_difficulty)
{
room_goto(Survival_medium_room)
}
else if place_meeting(x,224,obj_hard_difficulty)
{
room_goto(Survival_hard_room)
}

creators way is probably better if you wanted to try it as well (although I would change it so keyboard_check_pressed(vk_enter) is only used once the other ifs are inside it)
  • 0

#9 Devilfromhost12

Devilfromhost12

    GMC Member

  • GMC Member
  • 735 posts

Posted 27 May 2012 - 08:48 PM

I tried creators124's way and it worked. Thank you Jake Armstrong and creators124 for your guy's help. This topic is solved. :)
  • 0

#10 creators124

creators124

    awesomeliciousmember

  • GMC Member
  • 866 posts
  • Version:GM8

Posted 27 May 2012 - 09:55 PM

I tried creators124's way and it worked. Thank you Jake Armstrong and creators124 for your guy's help. This topic is solved. :)

you're welcome!
I use it to make options and it worked great for what you needed! :D
if you need help tell us! Posted Image Posted Image
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users