ZFGC

Resources => Coding => Topic started by: BlazeBigBang on October 09, 2012, 11:41:56 pm

Title: Trigger actions with buttons
Post 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?
Title: Re: Trigger actions with buttons
Post by: shongshui on October 10, 2012, 01:16:55 am
Use an if statement for keyboard_check().
Title: Re: Trigger actions with buttons
Post by: FrozenFire on October 10, 2012, 02:52:19 am
^ 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:
Quote from: code
if keyboard_check(ord("Z")){
     // put code for desired action in here
}
Title: Re: Trigger actions with buttons
Post by: Antidote on October 10, 2012, 03:21:44 am
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
Title: Re: Trigger actions with buttons
Post by: BlazeBigBang on October 10, 2012, 11:43:19 am
And which event should I add?
Title: Re: Trigger actions with buttons
Post by: 4Sword on October 10, 2012, 01:35:31 pm
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.

Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved