playMaker

Author Topic: Know last 'U Gui Button On Click' Event Source  (Read 983 times)

psypol

  • Playmaker Newbie
  • *
  • Posts: 39
    • View Profile
Know last 'U Gui Button On Click' Event Source
« on: July 03, 2018, 03:58:54 AM »
Hi

i searched the forum and echosystem for this.

is there a simple way to store the last button which generated an event via this action :


too bad this action does not have an additional param which would be "button script carrier" and we could store that in a gameobject variable.

in a state i have several stacked actions monitoring several buttons.
i was thinking about 3 ways to accomplish this but both feels overkill for me.
also each of these seems kinda viable if you just have 2 up to 5 buttons, but if you have way more buttons all look very complex to handle a simple problem.

1) on each of the buttons monitored : put an FSM-event call in OnClick() in the inspector. Call another FSM which has only one role : catch with a global transition event which button of the pool of buttons was the last pressed.

2) the simple stupid one : put a different event on EACH of the stacked actions, and save the clicked button in a global variable before doing anything else.
the problem is that this solution looks ugly to me. it visually pollutes the FSM.


3) -Does not work-
Right above each 'U Gui Button On Click' of my stack : put a "set gameobject" and store the button from the action right under in a variable (same variable for all onclick's).

given that the state will exit via one of the OnClick's it means that it will not execute the gameobject assignation lower than the actual button which was just pressed. As a result the variable would have the last pressed button saved.

Any suggestions to handle this the most clean and easily maintenable way ?
thanks.
« Last Edit: July 03, 2018, 04:19:15 AM by psypol »

psypol

  • Playmaker Newbie
  • *
  • Posts: 39
    • View Profile
Re: Know last 'U Gui Button On Click' Event Source
« Reply #1 on: July 03, 2018, 04:14:04 AM »
ok option 3 does not work
first all the gameobject assign actions are done and then ONLY all the Button On Click waits for a click.

verybinary

  • Junior Playmaker
  • **
  • Posts: 81
    • View Profile
    • The Museum of Digital
Re: Know last 'U Gui Button On Click' Event Source
« Reply #2 on: July 03, 2018, 06:07:00 AM »
make a global called "lastbutton". make it an gameobject
on your button, go to the onclick and have it kick off an event called "doit"
now create an FSM on your button, on state 1, add your "doit" event. lead your doit event to a new state, the first action in this new state should be "Get Owner" and set it to your "lastbutton" global.

psypol

  • Playmaker Newbie
  • *
  • Posts: 39
    • View Profile
Re: Know last 'U Gui Button On Click' Event Source
« Reply #3 on: July 03, 2018, 06:27:30 AM »
good suggestion.
i guess i need to put a wait of at least 0.1 in my main script to leave some time to the FSM of the clicked button do the action you talk about.

verybinary

  • Junior Playmaker
  • **
  • Posts: 81
    • View Profile
    • The Museum of Digital
Re: Know last 'U Gui Button On Click' Event Source
« Reply #4 on: July 03, 2018, 08:00:30 AM »
or...
since the lastbutton var can be always changing, the main script should be checking more than just once anyways and will be able to update itself when a button is pressed. and the doit event can lead to more than just a variable assignment. you can do anything you want to after that...

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4956
    • View Profile
    • jinxtergames
Re: Know last 'U Gui Button On Click' Event Source
« Reply #5 on: July 03, 2018, 10:44:20 AM »
Hi.

If you are using PlayMaker 1.9+ then you can use 'UI Button Array Index'

I just made this recently and this might be added to the official action (UI Button Array)

I used this on this tutorial  (@ about 19 minutes in the video) :


verybinary

  • Junior Playmaker
  • **
  • Posts: 81
    • View Profile
    • The Museum of Digital
Re: Know last 'U Gui Button On Click' Event Source
« Reply #6 on: July 03, 2018, 12:02:06 PM »
new way to do it all...
4 buttons
1 buttonmanager object
the buttonmanager has 4 global states named push1 through push4. each global event goes to a state that sets a local variable to 1 - 4, then on to the processing that would happen with that
onclick, each of the buttons each send their own state in button manager.

edit: I don't use global transitions, but also assumed transitions were different than variables, was just trying to give options. nevermind.
« Last Edit: July 04, 2018, 07:46:36 AM by verybinary »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4956
    • View Profile
    • jinxtergames
Re: Know last 'U Gui Button On Click' Event Source
« Reply #7 on: July 03, 2018, 04:01:48 PM »
Hi.
You should minimize using globals.
They are easy to hack and bad design practice.

check out this wikki for Best Practices