This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
new:input [2018/02/15 15:01] – created korshun | new:input [2018/02/17 12:10] (current) – korshun | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== | + | ====== |
- | Key states: | + | ACSUtils provides a set of wrappers for [[zdoom> |
- | * Up | + | ===== Basic concepts ===== |
- | * Down | + | |
- | * Pressed | + | |
- | * Released | + | |
+ | * Every key is either **up** or **down** at any time. | ||
+ | * If the key was up the previous tic, but is now down, it is said to have been **pressed**. | ||
+ | * If the key was down the previous tic, but is now up, it is said to have been **released**. | ||
+ | * If the key has been pressed or released, it is said to have been **toggled**. | ||
+ | |||
+ | ACSUtils provide a way to easily check these all these states for every key without writing compliated '' | ||
+ | |||
+ | ===== What's the point of " | ||
+ | |||
+ | Say, you have an on-screen button to sell items that can be [[mouse|clicked with mouse]]: | ||
+ | |||
+ | < | ||
+ | if (/* check that mouse cursor is inside the button */) | ||
+ | if (GetPlayerInput(-1, | ||
+ | SellItem(); | ||
+ | </ | ||
+ | |||
+ | **This code is wrong.** If the player clicks the button once, it will likely cause him to sell multiple items. That's because this code checks if the mouse button is **down**. But the mouse button may be down for multiple tics after a click, as it may not be immediately released. | ||
+ | |||
+ | To avoid this bug, you need to check if the button was up the previous tic, but is now down. And that's exactly what the **pressed** state means. The '' | ||
+ | |||
+ | < | ||
+ | if (/* check that mouse cursor is inside the button */) | ||
+ | if (KeyPressed(BT_ATTACK)) // check left mouse button click | ||
+ | SellItem(); | ||
+ | </ | ||
+ | |||
+ | Now the button works correctly. Performing an action on releasing the button can be done the same way using '' | ||
+ | |||
+ | ===== Functions ===== | ||
+ | |||
+ | To check one key or a key combination: | ||
+ | |||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | |||
+ | Examples: | ||
+ | |||
+ | Checking one key: | ||
+ | |||
+ | < | ||
+ | if (KeyPressed(BT_ATTACK)) | ||
+ | print(s:" | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | Checking a key combination: | ||
+ | |||
+ | < | ||
+ | if (KeyDown(BT_FORWARD | BT_BACK)) | ||
+ | print(s:" | ||
+ | s:"You are not going anywhere this way." | ||
+ | </ | ||
+ | |||
+ | <note important> | ||
+ | |||
+ | To check if at least one of the keys is in a given state: | ||
+ | |||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | |||
+ | For example: | ||
+ | |||
+ | < | ||
+ | if (KeyPressedAny(BT_ATTACK | BT_ALTATTACK)) | ||
+ | print(s:" | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | if (KeyDownAny(BT_FORWARD | BT_BACK | BT_MOVELEFT | BT_MOVERIGHT)) | ||
+ | print(s:" | ||
+ | </ | ||
+ | |||
+ | |||
+ | To use these wrappers on players other than the activator, prefix any of the above functions with '' | ||
+ | |||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||