PDA

View Full Version : Best way to change a button state from a different control?



Ogedei
February 7th, 2018, 16:45
I have a set of 6 buttons, representing attributes. I need to be able to select 2 of them at any given time.
Currently my set up has 3 values that are stored, Attribute1, Attribute 2 and Pointer.

Pointer starts at 1, clicking the button moves it to 2. Clicking it again moves it back to 1.

If the pointer is 1 then the attribute that is clicked on is stored in position 1
If the pointer is 2 then the attribute that is clicked on is stored in position 2

So if I have selected the second attribute and have decided I want to reselect them and click on a new attribute the pointer is set to 1 and the new attribute is placed in position 1.

The issue is clicking on the button moves the button from state 0 to state 1(which is what I want). But clicking on a different selection does not move the original button back to state 0.

My current plan is to add DB handlers to the buttons pointing at the two attributes. if the attributes change each button would query the two attributes. If the button name was no longer stored in either attribute it would set the button state to 0.

My question is, is that the best way to handle it? Is there a way for a button to change the state of another button from within LUA. ie if know the buttons name can I call it directly and set it's state to 0 somehow?

Trenloe
February 7th, 2018, 16:53
It's always a good idea to do it via the DB if possible. Plus, if you want the buttons to keep their states permanently, then you're going to have to use DB fields anyway. So, yes, go with DB fields and DB handlers.

Ogedei
February 7th, 2018, 17:26
It's always a good idea to do it via the DB if possible. Plus, if you want the buttons to keep their states permanently, then you're going to have to use DB fields anyway. So, yes, go with DB fields and DB handlers.

Sweet. Just wanted to make sure I wasn't barking up the completely wrong tree. :)

damned
February 7th, 2018, 23:01
And its so much easier to actually program when you just do it in the DB in the first instance.
One of many lessons Trenloe has imparted upon me...

Ogedei
February 7th, 2018, 23:08
And its so much easier to actually program when you just do it in the DB in the first instance.
One of many lessons Trenloe has imparted upon me...

I already have a lot of "intelligent" buttons monitoring values, so I thought I should double check with the pros before I continued on my merry way. Wasn't sure if they added a huge amount of overhead or something. :)

ie I have 3 sets of 5 affliction buttons that each look at a stat.

If you have a set of buttons like this:
O O O O O

and you click on two....

* O O O *

it would set the value of the affliction to 2, each of the buttons would monitor a change in the value, and see if they were equal to or less than. When complete you get...

* * O O O

Strictly aesthetic, but since they update the value I thought I would have them do that as well.

I have similar implemented on the "stress" boxes as well and they are 3 sets of 12.

;)