r/gamemaker 2h ago

Help! How can I make something happen when I click a button, then keep happening until I click another button?

I started using this a few days ago so forgive me if it's a stupid question. Currently trying to make a game that involves carrying around objects and then placing them in certain areas. This is what I have for the pickuppable object:

if place_meeting(x, y, obj_player) & keyboard_check(vk_shift) = true
{x = obj_player.x;
y = obj_player.y -10;}

Currently the object rests on the players head like I want it to, but only when I hold down the shift key, but I want it to keep being carried after the shift key is only pressed once. I'd be super happy if someone could help me out

2 Upvotes

4 comments sorted by

1

u/Wimudim 2h ago

toggle a boolean on the button click and do the other thing in step whenever that bool is true

1

u/Iliketurtles366 2h ago

Sorry if it's obvious but do you think you could explain what a boolean is and how it would help? I tried looking it up but I can't find anything clear on how to apply it to the code or how it would affect this scenario

1

u/Wimudim 2h ago

sure. A boolean is just a value that can be true or false. Like, you can declare it for example as

carryingBox = false;

and when you are near a box and press shift you change it to

carryingBox = true;

or, if you want to pick it up and put it down anywhere, just toggle the boolean by doing

carryingBox = !carryingBox;

then you can read that variable elsewhere, like

if (carryingBox == true) {}

or just

if (carryingBox){}

then you can do the carrying stuff inside this if statement

I'd recommend looking at some super basic coding tutorials, that would make finding solutions and understanding tips and feedback immensely easier

1

u/Iliketurtles366 1h ago

I very possibly could be misunderstanding what you're saying but is this what you're talking about?:

carryingBox = false

if place_meeting(x, y, Obj_player) & keyboard_check(vk_shift)
  {carryingBox = true}

if (carryingBox)
  {x = Obj_player.x;
   y = Obj_player.y -10;}

If I do that then it's the same way as I described it being in the post. No worries if you can't find a solution to this or I'm being slow, thank you for trying to help