ACSUtils Wiki

An ACS library for ZDoom-based ports

User Tools

Site Tools


new:input

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
new:input [2018/02/17 14:07] korshunnew:input [2018/02/17 14:09] 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, INPUT_BUTTONS) & BT_ATTACK)) // check left mouse button click     if (GetPlayerInput(-1, INPUT_BUTTONS) & BT_ATTACK)) // check left mouse button click
-        print("You sold one item");+        SellItem();
 </code> </code>
  
-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 ''KeyPressed'' function contains all the repetitive code to perform this check: 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 ''KeyPressed'' function contains all the repetitive code to perform this check:
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
-        print("You sold one item");+        SellItem();
 </code> </code>
  
Line 81: Line 81:
  
 <code> <code>
-if (KeyDown(BT_FORWARD | BT_BACK | BT_MOVELEFT | BT_MOVERIGHT))+if (KeyDownAny(BT_FORWARD | BT_BACK | BT_MOVELEFT | BT_MOVERIGHT))
     print(s:"You are trying to move.");     print(s:"You are trying to move.");
 </code> </code>
new/input.txt · Last modified: 2018/02/17 14:10 by korshun