Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: Trigger actions with buttons  (Read 3166 times)

0 Members and 1 Guest are viewing this topic.
Trigger actions with buttons
« on: October 09, 2012, 11:41:56 pm »
  • It's the grineer
  • *
  • Reputation: +17/-2
  • Offline Offline
  • Gender: Male
  • Posts: 1083
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?
Logged
Re: Trigger actions with buttons
« Reply #1 on: October 10, 2012, 01:16:55 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 57
Use an if statement for keyboard_check().
Logged
Re: Trigger actions with buttons
« Reply #2 on: October 10, 2012, 02:52:19 am »
  • AKA "Micah DS"
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1347
^ 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
}
Logged
  • My Music

Antidote

>.>
Re: Trigger actions with buttons
« Reply #3 on: October 10, 2012, 03:21:44 am »
  • In all seriousness who's serious?
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1485
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
Logged
  • Axiomatic Data Laboratories
Re: Trigger actions with buttons
« Reply #4 on: October 10, 2012, 11:43:19 am »
  • It's the grineer
  • *
  • Reputation: +17/-2
  • Offline Offline
  • Gender: Male
  • Posts: 1083
And which event should I add?
Logged
Re: Trigger actions with buttons
« Reply #5 on: October 10, 2012, 01:35:31 pm »
  • *
  • Reputation: +8/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6604
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.
Logged
Pages: [1]   Go Up

 


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



Page created in 0.163 seconds with 65 queries.

anything