Which array triggered button? (How do you do your grids/matrixes?)
travis
Posts: 180
say you have a couple arrays of button numbers and you stack them on a button event, how can you figure out which array the button is in?
[code]
DEFINE_CONSTANT
btns1[] = [1,16,99]
btns2[] = [13,2,5]
BUTTON_EVENT[tp,btns1]
BUTTON_EVENT[tp,btns2]
{
PUSH:{
//was this btns1 or btns2?
}
}
[code]
if the buttons are in some kind of order, you can do math to figure it out, but is there any trick for GET_LAST or something like that?
This must come up all the time for grids of buttons, like a matrix switcher.
I did it with a bunch of math, but it was pain. At least now I have an include of a bunch of Grid functions.
I'm coming back to it a few months later, thinking there must be an easy way. But when I started, it turned out to be just as much work.
[code]
DEFINE_CONSTANT
btns1[] = [1,16,99]
btns2[] = [13,2,5]
BUTTON_EVENT[tp,btns1]
BUTTON_EVENT[tp,btns2]
{
PUSH:{
//was this btns1 or btns2?
}
}
[code]
if the buttons are in some kind of order, you can do math to figure it out, but is there any trick for GET_LAST or something like that?
This must come up all the time for grids of buttons, like a matrix switcher.
I did it with a bunch of math, but it was pain. At least now I have an include of a bunch of Grid functions.
I'm coming back to it a few months later, thinking there must be an easy way. But when I started, it turned out to be just as much work.
0
Comments
Here is one generic way to tell what row and column was pushed inside an array of grid buttons and it’s easily configurable.
I’ve seen a better way of doing this calculation but I can’t remember where or how:
If anyone knows please post it.
I don't think that will work.
Took me way too long, but here are my functions with no IFs
These are for the other way to align the grid (sometimes you aren't the one who numbers things):
{
1,4,7,
2,5,8,
3,6,9
}
If you are referring to the code I posted, it doesn't matter what the button numbers are. Button numbers themselves don't mean a thing in this case, they're just used as placeholders. It will work with whatever button numbers, whatever amount of rows, and whatever amount of columns. Aside from the constants, the code doesn't need to change.
I don't think those functions will work. Try pushing button 15 (button index 5) and it should be row 1 column 5. The functions above will return row 2 column 2.
Paul
Even trying it like this so that the arrays are built into the event table works in the same bizarre manner.
I'm going to write another set to work with GET_LAST...
How did you work the feedback on this problem?
nBtn1 = get_last (btns1);
nBtn2 = get_last (btns2);
if theres a match one var will be 0 and the other will hold the index value. Then if/else if
I stopped using the GET_LAST function a year or so ago, when I was getting inconsistent results from it with the code I was writing at that time. Of course I don't recall the exact issue I was a having, but I stopped trusting some innate Netlinx functions because they sometimes didn't work as expected, and became very frustrating to track down.
There was another one that was giving me fits but I can't remember it at the moment.
I suppose maybe the issues I encountered with those functions have since been resolved.
Given a consistent result, I agree your recommendation would be simpler.