Page 1 of 1

Tinting buttons by iteration

PostPosted: Wed Mar 11, 2020 6:23 pm
by dantronic
Hi there,

I'm running a routine where you press one of a set of buttons, it turns that one green and the rest purple.
It relies on iterating through the button IDs, though, and keeping a sequence of consecutive IDs for these buttons has been problematic.

Adding buttons to the sequence... for a number of reasons can't keep them in sequence.

So is there a better way folks have done this whole idea? Seems like would be in common use

Thanks!
dan

Re: Tinting buttons by iteration

PostPosted: Thu Mar 12, 2020 8:12 am
by malkuth23
Hey Dan!

I am a bit confused and maybe I am misunderstanding your ask.
But I will pretend like I understand and say words that are 50% likely to not be helpful to you.

Here is what I usually do.
I create a macro or function that turns everything purple, then it turns the one you pressed green.
In the macro there would be clever for loops if they can exist, or you can copy and paste the command x number of times and just modify the button ids.
Either way, it works.

I also like to send a block of widgets into a different power of 10. So all my buttons will be 1001,1002 etc, which keeps me out of the garbage I made earlier.

When you say sequence, do you mean keep them in a row in WD or apply them to a PB sequence in some way?

Anyway, like I said, not sure I was helpful at all, but call me up sometime brother and we will invent a super-convoluted way to do this that we will never share with anyone because of it's complete absurdity.

Matt

Re: Tinting buttons by iteration

PostPosted: Thu Mar 12, 2020 8:21 am
by malkuth23
Oh wait. Maybe I got it.

Context.WidgetID - This will get you your buttonID. As long as you keep all the buttons in a reserved range say 1000-20000, then you run a loop to make them all purple, then use the context.widgerID to make the special button pink or whatever color you wanted.

If you really need a hard list, I think you could use this to make a list by putting the code in each button and press them and then have them send their ID to a list variable. Then you could just run down the list variable make each button rainbowtastic.

Re: Tinting buttons by iteration

PostPosted: Thu Mar 12, 2020 4:21 pm
by justyn roy
There are two ways I usually do this:

Method 1:

Set an array with all of your button IDs:

Code: Select all
Var ButtonList = [113,114,115,229,230...]

For i = 0 to ButtonList.Count - 1 {
    WDCustomScriptTint(i,255,0,255)
}


This way, you can easily add more buttons to that list in the top line, and the loop will automatically expand or shrink with that list.

Method 2:

Change the title of each of those buttons because the label can be different from the ID!:
Button 1 would be: MyNameHere_101 / MyNameHere_102

Then your script could be like this:
Code: Select all
Var NumOfButton = 100

For i = 101 to 101 + NumOfButton {
    Project.CustomScript("MyNameHere_" + i).SetTint(R,G,B)
}



Method 1 is probably the easiest now that you've already got a project on the go.

Let me know if that helps!

Re: Tinting buttons by iteration

PostPosted: Thu Mar 12, 2020 9:13 pm
by Benni_M
Hi Dan,

here is another solution with less performance.

create a integer variable e.g. var_last_tint.

Code: Select all
WDCustomScriptTint(var_last_tint,255,0,255)
var_last_tint = Context.WidgetID
WDCustomScriptTint(var_last_tint,0,0,255)


this code you have to add in all buttons or to a macro and pass the ID in the macro.

pros are that you don't have to think about button IDs ... and it's faster because you tint just 2 buttons all the time...
and you can easily create groups. You just have to change the variable.

Best,
Benni

Re: Tinting buttons by iteration

PostPosted: Fri Mar 13, 2020 2:51 pm
by dantronic
These are all great options thanks guys!

Inevitably they account for the non-consecutive nature of the IDs, which was the obstacle.

Trying to use re-use IDs from old deleted buttons -> wierd behavior, so a list or macro is the way to go