This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| new:input [2018/02/17 12:07] – korshun | new:input [2018/02/17 12:10] (current) – korshun | ||
|---|---|---|---|
| Line 14: | Line 14: | ||
| ===== What's the point of " | ===== What's the point of " | ||
| - | Say you have an on-screen button to sell items that can be [[mouse|clicked with mouse]]: | + | 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 (/* check that mouse cursor is inside the button */) | ||
| if (GetPlayerInput(-1, | if (GetPlayerInput(-1, | ||
| - | | + | |
| </ | </ | ||
| - | 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. | + | **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 '' | 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 '' | ||
| Line 29: | Line 29: | ||
| if (/* check that mouse cursor is inside the button */) | if (/* check that mouse cursor is inside the button */) | ||
| if (KeyPressed(BT_ATTACK)) // check left mouse button click | if (KeyPressed(BT_ATTACK)) // check left mouse button click | ||
| - | | + | |
| </ | </ | ||
| Line 81: | 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:" | ||
| </ | </ | ||