playMaker

Author Topic: Get information of which UI button was pressed?  (Read 1919 times)

playsteven

  • Junior Playmaker
  • **
  • Posts: 75
Get information of which UI button was pressed?
« on: June 15, 2018, 12:51:44 PM »
The new UI actions look great but what would be the best way to do the following?

I have 16 buttons and I want to know the number of which button was pressed.

I'm thinking of using UI Button Array, but do I have to add a separate state for each button to set the button number?  Or is there a way to have only one state which knows which button 1..16 was pressed?

verybinary

  • Junior Playmaker
  • **
  • Posts: 81
    • The Museum of Digital
Re: Get information of which UI button was pressed?
« Reply #1 on: June 15, 2018, 02:29:02 PM »
You should be able to do it all in one state...
How would depend on what you are trying to do, and how your buttons are set up.

If this was a calculator, each of the buttons would have names like 1, 2, 3 etc.
my array manager object would set values for all indexes would wait for input, get button pressed as the buttons number and set userInput to array(#).

if the 5 button was pressed, it would get index 5 from my array, and set the userInput variable to whatever value array(5) has.

if this isn't a calculator, the buttons would send its index number to the manager.

this can actually be done in very multiple ways. try however you think would be easiest to manage it later.

playsteven

  • Junior Playmaker
  • **
  • Posts: 75
Re: Get information of which UI button was pressed?
« Reply #2 on: June 15, 2018, 07:04:26 PM »
Thanks @verybinary for your help :)

I found another way too. I've named the triggered events 01, 02, 03.. etc and then I use Get Last Event to capture the button number.

Hope these suggestion help somebody else!

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7614
    • jinxtergames
Re: Get information of which UI button was pressed?
« Reply #3 on: June 16, 2018, 09:18:05 AM »
Hi.
To know which button is click would be very useful indeed (in many cases) on this action....

Sooo i made a custom version where you can get the index of the button clicked.

Then that index nr you can use for example on an array.

Can you guys give it a try (attachment below)  and some feedback.

If its good i will try to ask to Alex to add this to the official action, else i will place this on the Ecosystem.
But maybe a Ugui version then (else it starts to get messy using both ui and ugui in the ecosystem)
« Last Edit: June 16, 2018, 02:51:31 PM by djaydino »

playsteven

  • Junior Playmaker
  • **
  • Posts: 75
Re: Get information of which UI button was pressed?
« Reply #4 on: June 17, 2018, 05:15:56 AM »
Thanks @djaydino I think this enhances the action :)

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7614
    • jinxtergames
Re: Get information of which UI button was pressed?
« Reply #5 on: June 17, 2018, 10:53:36 AM »
Hi,
I think so to.

i also made 1 that can be used with an array (which includes the buttons)
This makes it so that buttons can be added/removed @ runtime.

But there is still a small issue that any array can be placed in it and i am tryng to make it so that only a 'Ui.Button' array can be used or a gameobject array that includes the Ui.Button

playsteven

  • Junior Playmaker
  • **
  • Posts: 75
Re: Get information of which UI button was pressed?
« Reply #6 on: June 18, 2018, 04:18:11 AM »
Your efforts are very much appreciated @djaydino