This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Next revisionBoth sides next revision | ||
new:input [2018/02/17 14:07] – korshun | new:input [2018/02/17 14:08] – korshun | ||
---|---|---|---|
Line 19: | Line 19: | ||
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 | ||
- | | + | |
</ | </ | ||