btnp = "button pressed"
btnp( index, [player] )
|index||a button number or button symbol (see chart below)|
|player||(optional) a player number (0-7)|
If you hold the button down, this will only return true once because it also checks if on the last frame the button was not pressed. However, if you hold the button down for longer than 15 frames, then this resets and does return true. It will then continue to return true every 4 frames after that.
For multiplayer games, you will need to include player numbers (0-7).
These are the button indexes you can use:
Custom Delay Length
You can set your own button delay by poking memory
0X5F5C like this:
You can set it to 255 to stop the
btnp from resetting automatically at all, so that the player must release the button and press again for it to trigger again.
You can set your own repeating delay by poking memory
0X5F5D like this:
In order to detect the button input for a multiplayer game, you will need to include the second argument for the player number.
btn( button_number, player_number )
If you understand how to use tables and loops, you can use these to help you write less code, even when you need to check for buttons of multiple players. For example, you can use a for loop to check the same button inputs for each player in one block of code:
num_players=2 for i=0, num_players-1 do if btnp(0,i) then --left button pressed --i = which player end end
One thing to keep in mind is that the player index used in this function's second argument starts at 0, not 1. So player 1 is index 0 and player 8 is index 7. This is why the above loop starts at zero, and ends at one less than the total number of players.
17 Oct 2023