playMaker

Author Topic: Read which button was pressed?  (Read 4037 times)

justifun

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 280
Read which button was pressed?
« on: June 29, 2011, 02:38:42 PM »
Is there a way to determine which button has been pressed and store that as a string without having to test for all button possibilities?

Duffdaddy

  • Junior Playmaker
  • **
  • Posts: 54
Re: Read which button was pressed?
« Reply #1 on: June 30, 2011, 05:49:20 AM »
How about just broadcasting an event on a button press?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Read which button was pressed?
« Reply #2 on: June 30, 2011, 05:54:14 AM »
Hi,

 needs more details for an accurate reply. do you mean Mouse buttons or inputs buttons, or gui buttons?

 for gui buttons: http://unity3d.com/support/documentation/ScriptReference/Event-button.html

 for mouse buttons, you have to build a fsm that listen to all your inputs. I agree with you on this, there should be a way to be notified precisly about input events without having to hardcode everything. Maybe there is one way, but I am not aware of it. search/Ask unity Answers, you will certainly get some reply.

 Hope it helps,

 Bye,

 Jean

justifun

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 280
Re: Read which button was pressed?
« Reply #3 on: June 30, 2011, 04:02:47 PM »
Yeah i was hoping to simplify my graph by having all of my movement states exit with a transtion that would enter into one main state that would check which button was pressed (on the controller) and then transition out to various different actual movement states.  This way i wouldnt have to have multiple repeating button checks in every initial movement state.

eg (what i want to avoid):
Walking
-ifJump ->
-ifRun ->
-ifAttack ->

Running
-ifJump ->
-ifRun ->
-ifAttack ->


(What i would like to do)

Walking
-UserButtonPress -> Which button was pressed? - > goto appropriate state

the Get Key action would work if there was an option to store the result as a string instead of a bool
https://hutonggames.fogbugz.com/default.asp?W348


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Read which button was pressed?
« Reply #4 on: July 01, 2011, 07:26:05 AM »
Hi,

 For this ( and many other usage), I recommend you build an input "broker" that basically is your interface for any input.

 This way you have one place where you hard code each input and can then send a generic event containing informations about the input ( using events' data system) OR send instead a more appropriate event defining the action to do. This is a very powerful technic because you separate the user inputs from the logic and therefore you can control your game without the user, this is useful for cut scenes, or when a behavior can be triggered in different context, user input or via logical steps or reactions from the game engine itself.

 So in your particular example, you would fill an event data string with "jump" for example, and send the event globally or else, then each interested fsm having this global event define, would catch that and check the string data of that event and act upon this.

check these two actions:
https://hutonggames.fogbugz.com/default.asp?W531
https://hutonggames.fogbugz.com/default.asp?W530

 Hope that helps,

 Bye,

 Jean

justifun

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 280
Re: Read which button was pressed?
« Reply #5 on: July 01, 2011, 11:13:40 AM »
Thanks Jean

I think i understand what you are saying, but would you be able to make a screenshot or a sample scene for me so i can fully visualize what you mean?

Thank you for your time.