This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
new:input [2018/02/16 21:12] – korshun | new:input [2018/02/17 12:10] (current) – korshun | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Input functions | + | ====== Input library |
ACSUtils provides a set of wrappers for [[zdoom> | ACSUtils provides a set of wrappers for [[zdoom> | ||
Line 5: | Line 5: | ||
===== Basic concepts ===== | ===== Basic concepts ===== | ||
- | Every key is either **up** or **down** at any time. | + | * 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**. | ||
- | If the key was **up** the previous tic, but is now **down**, it is said to have been **pressed**. | + | ACSUtils provide a way to easily check these all these states for every key without writing compliated '' |
- | If the key was **down** the previous tic, but is now **up**, it is said to have been **released**. | + | ===== What' |
- | If the key has been **pressed or released**, it is said to have been **toggled**. | + | Say, you have an on-screen button to sell items that can be [[mouse|clicked with mouse]]: |
- | ACSUtils provide a way to easily | + | < |
+ | if (/* check that mouse cursor is inside the button */) | ||
+ | if (GetPlayerInput(-1, INPUT_BUTTONS) & BT_ATTACK)) // check left mouse button click | ||
+ | SellItem(); | ||
+ | </ | ||
- | ===== What's the point of " | + | **This code is wrong.** If the player clicks the button once, it will likely cause him to sell multiple items. That' |
+ | |||
+ | 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 ===== | ===== Functions ===== | ||
Line 32: | Line 49: | ||
< | < | ||
- | if (KeyPressed(BT_FORWARD)) | + | if (KeyPressed(BT_ATTACK)) |
- | print(s:" | + | print(s:" |
</ | </ | ||
Line 64: | Line 81: | ||
< | < | ||
- | if (KeyDown(BT_FORWARD | BT_BACK | BT_MOVELEFT | BT_MOVERIGHT)) | + | if (KeyDownAny(BT_FORWARD | BT_BACK | BT_MOVELEFT | BT_MOVERIGHT)) |
print(s:" | print(s:" | ||
</ | </ | ||
- | To use these wrappers on players other than the activator, prefix any function | + | To use these wrappers on players other than the activator, prefix any of the above functions |
* '' | * '' |