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.

One if cond. that checks if a group of buttons were pressed instead of multple?

PK8

Member

Sorry for the sucky thread title. Anyway, in this one script I've submitted, I was kinda forced to use a crapload of if conditions to check if buttons  A, B, C, X, Y, Z, L, R, F5, F6, F7, F8, F9, UP, DOWN, LEFT, RIGHT, ALT, CTRL or SHIFT was being pressed.

Code:
	  #Buttons
	  if Input.trigger?(Input::R) or Input.trigger?(Input::L)
		break
	  end
	  if Input.trigger?(Input::A) or Input.trigger?(Input::B)
		break
	  end
	  if Input.trigger?(Input::C) or Input.trigger?(Input::X)
		break
	  end
	  if Input.trigger?(Input::Y) or Input.trigger?(Input::Z)
		break
	  end
	  if Input.trigger?(Input::UP) or Input.trigger?(Input::DOWN)
		break
	  end
	  if Input.trigger?(Input::LEFT) or Input.trigger?(Input::RIGHT)
		break
	  end
	  if Input.trigger?(Input::ALT) or Input.trigger?(Input::CTRL)
		break
	  end
	  if Input.trigger?(Input::SHIFT) or Input.trigger?(Input::F5)
		break
	  end
	  if Input.trigger?(Input::F6) or Input.trigger?(Input::F7)
		break
	  end
	  if Input.trigger?(Input::F8) or Input.trigger?(Input::F9)
		break
	  end
	  #Buttons End

Is there a better way to check if one of multiple buttons were being tapped instead of doing that? Am I missing something?  :crazy:
 
Well, you can make it a bit more compact by making it one if statement (things like an "or" at the end of a line makes the next line act like part of it)

Code:
  #Buttons
  if Input.trigger?(Input::R) or Input.trigger?(Input::L) or
        Input.trigger?(Input::A) or Input.trigger?(Input::B) or
        Input.trigger?(Input::C) or Input.trigger?(Input::X) or
        Input.trigger?(Input::Y) or Input.trigger?(Input::Z) or
        Input.trigger?(Input::UP) or Input.trigger?(Input::DOWN) or
        Input.trigger?(Input::LEFT) or Input.trigger?(Input::RIGHT) or
        Input.trigger?(Input::ALT) or Input.trigger?(Input::CTRL) or
        Input.trigger?(Input::SHIFT) or Input.trigger?(Input::F5) or
        Input.trigger?(Input::F6) or Input.trigger?(Input::F7) or
        Input.trigger?(Input::F8) or Input.trigger?(Input::F9)
    break
  end
  #Buttons End

But it looks like you want it to break if you press anything, and I dunno if there's a better way to check for that. Seems like there should be.
 
Code:
[Input::R, Input::L, Input::A, Input::B, Input::C, Input::X, Input::Y, Input::Z, Input::UP, Input::DOWN,
  Input::LEFT, Input::RIGHT, Input::ALT, Input::CTRL, Input::SHIFT, Input::F5, Input::F6, Input::F7,
  Input::F8, Input::F9].each { |k| break if Input.trigger?(k) }
 

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