is Button Pressed
Check if a controller button for a player is pressed or not.
mp.isButtonPressed(mp.playerSelector(mp.PlayerNumber.One), mp.MultiplayerButton.A)
Parameters
- player: the player to check the controller button state for.
- button: the controller button to check for a pressed condition.
Returns
- a boolean value for the state of the button for the player. It is
true
if the button is pressed andfalse
if the button is not pressed.
Example
If player 2
is pressing the up arrow button for too long, thenplayer 1
wins.
let pressCount = 0
game.onUpdateInterval(500, function () {
if (mp.isButtonPressed(mp.playerSelector(mp.PlayerNumber.Two), mp.MultiplayerButton.Up)) {
pressCount += 1
if (pressCount > 1) {
mp.gameOverPlayerWin(mp.playerSelector(mp.PlayerNumber.One))
}
} else {
pressCount = 0
}
})
See also
on button pressed, move with buttons
multiplayer