What are the differences between the different keypress commands?

From OHRRPGCE-Wiki
Jump to navigationJump to search

key is pressed[edit]

The key is pressed command works for any key on the keyboard, and will tell you if the key is being pressed right at the instant the command is run. It does not wait, it just tells you what the key is doing right now. Here is a typical example of its use:

if (key is pressed(key:up)) then, begin
  my jump script
end

If you need to wait for a certain key to be pressed, you can use the wait for scancode command. It uses the same key constants as key is pressed. Alternatively, you could write you own while loop to wait for a keypress, if you need the waiting to stop under certain conditions. See the Scripts:Skippable wait script. Your while loop must contain a wait(1) command, because key is pressed returns the keyboard state at the beginning of this tick. It does not query the keyboard again.

The command 'key is pressed' uses the constants key: left, key: L, key: esc, etc, which may be found in scancode.hsi and in the plotdictionary entry for key is pressed.

wait for key[edit]

The wait for key command waits for the player to press a key. It stops the script until the key is pressed. If the argument is "any key", then it returns the scancode of the pressed key.

The "wait for key" command use the following constants: upkey, downkey, leftkey, rightkey, usekey, cancelkey, menukey, anykey.

Please note that:

  • The two sets of constants are not interchangeable. You can't use "upkey" instead of "key:up" with the "wait for key" command.
  • "use key" means SPACE or ENTER or CTRL or joystick button 1, "cancel key" means ALT or ESC or joystick button 2, "menu key" is the same as "cancel key".
  • Writing "wait for key" without any brackets is the same as writing "wait for key (any key)" (The argument defaults to any key)

Wait for scancode[edit]

For those who could have forgot about scancodes, the scancodes represent keys on the the keyboard. Each key has its own scancode, though there may be multiple symbols on the key.

Now about the command itself. Waits for scancode is a command that make the player waits to press a specific key. The specific key in question will be a constant already used by the command key is pressed

show text box(314) # "press F!"
wait for scancode(key:F)

To conclude[edit]

The difference is what they take. wait for key takes a parameter like use key or any key, where wait for scancode takes something such as key:a. In both situation, the game will wait until the specified key is pressed. So we can conclude that the 2 commands are slightly difference and can be useful in the same kind of situation.

If you still have doubts and don't which one to use, feel free to ask on the forums!

See Also[edit]