Skip to content
StinkerB06 edited this page May 23, 2018 · 25 revisions

btnp

btnp [[id: 0..31], [hold], [period] ] -> pressed (but wasn't pressed in previous frame)

Parameters:

  • id : The id of the key we need to interrogate, see the key map for reference
  • hold : The time (in ticks) the key must be pressed to call period.
  • period : Within the amount of time (in ticks) after that, this function will return true again.

Description:

This function allow to read the status of one of the buttons attached to TIC. The function return true value only in the moment the key is depressed.
You can also argument the hold and period parameters that allows to return true keeping the key pressed. After the hold time is elapsed the function return true every time period is passed.
Time is expressed in ticks; at 60 fps it means you need to use 120 to wait 2 seconds.

Example:

Example

-- btnp demo: move the rectangle in 10 pixels step, 
-- every time one direction keys is pressed.
-- Keep the key pressed for more than 1 second to have
-- the rectangle move every tenth of seconds.

x=120
y=80

cls(12) 
function TIC()

    if btnp(0,60,6) then y=y-10 end
    if btnp(1,60,6) then y=y+10 end
    if btnp(2,60,6) then x=x-10 end
    if btnp(3,60,6) then x=x+10 end

    rect(x,y,10,10,8)       
end
Clone this wiki locally