Multi-dimension array definition?
fogled@mizzou
h4x354x0r
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,
Comments
-
I think I know what you're asking, and the answer is no. Arrays have to start at index 1.
-
You are correct, dimensions always start at 1. For a simpler solution to the problem you're showing, try something like
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 -
jweather wrote:Basically, GET_LAST and the btnARRAY give you your mapping from (121,122,123...) back to (1, 2, 3...) which are your array indices.
Oh... the light bulb goes on...
Thank you very much! -
You can create multi dimensional arrays, you can even use them in Structures:fogled@mizzou wrote:It appears that I cannot create my own "offset" index for multi-dimension arrays.integer multiD[2][3][3]; //multiD[house][floor][room] multiD[1][1][1] = 11; multiD[1][2][2] = 12; multiD[1][3][3] = 13; multiD[2][1][1] = 21; multiD[2][2][2] = 22; multiD[2][3][3] = 23;
-
Use a wrapper function
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. -
I prefer to make a CONSTANT list defining my array elements, so instead of having to reference the numbers, I can have readable indexes.
-
DHawthorne wrote:I prefer to make a CONSTANT list defining my array elements, so instead of having to reference the numbers, I can have readable indexes.
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. -
What I think he is talking about is say the first index of the array represents rooms.
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. -
Exactlyalexanbo wrote:What I think he is talking about is say the first index of the array represents rooms.
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.
Sorry if I wasn't clear. -
alexanbo wrote:Living = 1
Dining = 2
Den = 3
Thanks everyone! I think I've got a handle on this now. On to the next question...
Categories
- All Categories
- 2.5K AMX General Discussion
- 922 AMX Technical Discussion
- 514 AMX Hardware
- 502 AMX Control Products
- 3 AMX Video Distribution Products
- 9 AMX Networked AV (SVSI) Products
- AMX Workspace & Collaboration Products
- 3.4K AMX Software
- 151 AMX Resource Management Suite Software
- 386 AMX Design Tools
- 2.4K NetLinx Studio
- 135 Duet/Cafe Duet
- 248 NetLinx Modules & Duet Modules
- 57 AMX RPM Forum
- 228 MODPEDIA - The Public Repository of Modules for Everyone
- 943 AMX Specialty Forums
- 2.6K AMXForums Archive
- 2.6K AMXForums Archive Threads
- 1.5K AMX Hardware
- 432 AMX Applications and Solutions
- 249 Residential Forum
- 182 Tips and Tricks
- 146 AMX Website/Forums