Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

On-Press Buttons - How to?

Hey,

I have a question about making switches (event; not actual switches like $game_switches[44]) in-game. In particular the one which activates when you step on it (gets pressed) and deactivates when you step off (isn't pressed in anymore). How do I make it so that it deactivates when you step off? Also, do you know how to make it activate/deactive by shoving an object onto it?

If there's already a tutorial out there, please link me to it if you have it, but I couldn't find one about making switches in-game at all. :/

Thank you!!
 

khmp

Sponsor

Through events I can only think that you would need a parallel process event to constantly gather the player's position in relation to the switch. When the positions are the same enable the switch else disable the switch. In the case of the object that can be moved you can keep gathering its coordinates every time its activated. In the parallel process event you can have another conditional testing the movable events location against the floor switch's location. Using the same logic above if their positions' are the same enable the switch otherwise disable the switch.

But keep in mind that if the player is on the floor switch the other movable event can not be at the same location, and vice versa. So place one of the conditionals I mentioned above into the else portion of of the other conditional. For example:

Parallel Process Event:
variable[1] = players.x
variable[2] = players.y
variable[3] = floor_switch.x
variable[4] = floor_switch.y
variable[5] = movable_event.x
variable[6] = movable_event.y
if variable[1] == variable[3] && variable[2] == variable[4]
  switch[1] = true
else
  if variable[5] == variable[3] && variable[6] == variable[4]
    switch[1] = true
  else
    switch[1] = false
  end
end

Does that help visualize what you need to do?

Good luck with it Twin Matrix! :thumb:
 
You can alternatively use four invisible events one tile away from the switch. Set them to Player Touch, and make them deactivate the event if the player is facing the direction away from the switch. Remember to check if the movable event is on there first.

Well, that's three handy options right there. If you're using VX, you can also use Hevendor's "Eventer's Toolbox" script, it makes everything even easier. Good luck with it.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top