Syntax: keydown(int)
Returns boolean.


Returns true when the specified key is pressed.

The "specified key" is expressed as a magical integer value which works the same way as the one keyname accepts.

Using standard keys, going from 0 through 10, you can define the numbers thusly: up, left, down, right, S, A, D, M, tab, Q, P

keydown(1) is true when the left key is pressed.
keydown(9) is true when the inventory (Q) button is down.


function onCreated()
  this.speed = 2;

function onTimeout()
  // They keys for movement are arbitrarily defined as 0 to 3, where 0 is up and 3 is right, going counter-clockwise.
  for (temp.i = 0; i < 4; i ++)
	// Here's the actual check to see if the player is holding the up/left/down/right key down.
	if (keydown(i))
	  // If this is true, we move the player in that direction.
	  player.x += vecx(i) * this.speed;
	  player.y += vecy(i) * this.speed;
	  // By coincidence, the numbers 0 through 3 also work as the four compass directions, which vecx and vecy accepts as arguments.

... will work as a simple form of 'boots'.

function onKeyPressed()
  if (keydown(5))
	echo("The sword key was pressed.");

... will echo when a key is pressed and the slash key happens to be down at the same time.



There are no comments on this page. [Add comment]

Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by WikkaWiki