Multi-dimension array definition?
It appears that I cannot create my own "offset" index for multi-dimension arrays. This works, and I get the values from the multi-dim array on the button push:
...and the following compiles OK, but I do not get the values from the multi-dim array:
So It appears that I cannot specify what the value of that first dimension is, I just have to live with an auto-index starting at 1?
Is there a way to get an offset index for the first dimension of a muti-dim array?
Thanks,
DEFINE_CONSTANT
integer lvl_mic_preval[][] = {
{1,3,0},
{2,4,0},
{3,5,0}
}
DEFINE_EVENT
button_event[tp,121]
{
push:
{
send_string debug,"'DEBUG: preset_val: 1=',itoa(lvl_mic_preval[button.input.channel - 120][1]),'; 2=',itoa(lvl_mic_preval[button.input.channel - 120][2]),'; 3=',itoa(lvl_mic_preval[button.input.channel - 120][3])"
}
}
...and the following compiles OK, but I do not get the values from the multi-dim array:
DEFINE_CONSTANT
integer lvl_mic_preval[][] = {
121,{1,3,0},
122,{2,4,0},
123,{3,5,0}
}
DEFINE_EVENT
button_event[tp,121]
{
push:
{
send_string debug,"'DEBUG: preset_val: 1=',itoa(lvl_mic_preval[button.input.channel][1]),'; 2=',itoa(lvl_mic_preval[button.input.channel][2]),'; 3=',itoa(lvl_mic_preval[button.input.channel][3])"
}
}
So It appears that I cannot specify what the value of that first dimension is, I just have to live with an auto-index starting at 1?
Is there a way to get an offset index for the first dimension of a muti-dim array?
Thanks,
0
Comments
DEFINE_CONSTANT integer btnARRAY[] = {121, 122, 123} integer lvl_mic_preval[][] = { {1,3,0}, // 121 {2,4,0}, // 122 {3,5,0} // 123 } DEFINE_EVENT button_event[tp,btnARRAY] { push: { send_string debug,"'DEBUG: preset_val: 1=',itoa(lvl_mic_preval[GET_LAST(btnARRAY)][1]),'; 2=',itoa(lvl_mic_preval[GET_LAST(btnARRAY)][2]),'; 3=',itoa(lvl_mic_preval[GET_LAST(btnARRAY)][3])" } }Basically, GET_LAST and the btnARRAY give you your mapping from (121,122,123...) back to (1, 2, 3...) which are your array indices.
Untested, please excuse any think-os.
Jeremy
Oh... the light bulb goes on...
Thank you very much!
If you always refer to the array via wrapper functions, you can code the easy-to-get-wrong bit(s) just once and use them with confidence thereafter. Think object oriented.
Any possibility you could expound on that just a bit? I'm not sure I understand what you mean. I'm trying to define a constant, and I can't get anything but numbers - not of my own choosing - for indexes.
In your constants you'd do something like
Living = 1
Dining = 2
Den = 3
Then when referencing the array you can write
[Living][blah]
If you got real ambitious you might be able to use Hash Maps and such in Java on the Duet side.
Thanks everyone! I think I've got a handle on this now. On to the next question...