ZFGC
Resources => Coding => Topic started by: BlazeBigBang on October 09, 2012, 11:41:56 pm
-
So, I'd like to know how to, for example, when pressing the "A" button close to an NPC to talk with it, or when pressing "B" button, to use the sword. Would anyone help me at this?
-
Use an if statement for keyboard_check().
-
^ this. Also, if you want to use letters, you will need to use "ord()".
For example, if you want the "Z" key to do something, type this:
if keyboard_check(ord("Z")){
// put code for desired action in here
}
-
On top of that you need to check if your player object is an appropriate distance from the NPC in question or you'll get weird results :P
-
And which event should I add?
-
If you just want to check to see if a key is pressed (when the key goes from a state of not being hit to being hit), you can more easily use the events for keyboard pressed. If you want to monitor the key when its being held (when the key goes from a state of not being hit to being hit, and until the key is released) then with other game code for things like walking and stuff having the code for that in Step event works better.
Something like a sword though, if you are just swinging it, then a key press would work fine. Also though, if you are bringing up a textbox, key pressing also works fine.