And just when I got all excited...
ericmedley
Senior Member - 3709 Posts
I was goofing around with a new program and tried this:
... wondering if this would work. And lo and behold, it compiled just fine!
I was hoping it would populate the first cell with a '7'
Finally, the secret to my uniform code at last! I can simply keep adding or subtracting touch panels and my arrays grow and shrink with them. However, in debug I found out that it doesn't actually work. The array gets built by 1 dimention in that cell. :P
DEFINE_DEVICE
dv_AW_TP_Nav_01 = 10001:01:0 // Game Room 5" Wireless
dv_AW_TP_Nav_02 = 10002:01:0 // Kevin's Room 5" In Wall
dv_AW_TP_Nav_03 = 10003:01:0 // Living Room 5" Wireless
dv_AW_TP_Nav_04 = 10004:01:0 // Kitchen 5" Wireless
dv_AW_TP_Nav_05 = 10005:01:0 // Study 4" In Wall
dv_AW_TP_Nav_06 = 10006:01:0 // Guest Apt 5" In Wall
dv_AW_TP_Nav_07 = 10007:01:0 // Master Bed 5" Wireless
DEFINE_VARIABLE
volatile DEV dev_AW_TP_01[]=
{
dv_AW_TP_Nav_01 // Game Room 5" Wireless
,dv_AW_TP_Nav_02 // Kevin's Room 5" In Wall
,dv_AW_TP_Nav_03 // Living Room 5" Wireless
,dv_AW_TP_Nav_04 // Kitchen 5" Wireless
,dv_AW_TP_Nav_05 // Study 4" In Wall
,dv_AW_TP_Nav_06 // Guest Apt 5" In Wall
,dv_AW_TP_Nav_07 // Master Bed 5" Wireless
}
// and here it is...
volatile AW_TV_POPUP_NAME[length_array(dev_AW_TP_01)][200][40]
... wondering if this would work. And lo and behold, it compiled just fine!
I was hoping it would populate the first cell with a '7'
Finally, the secret to my uniform code at last! I can simply keep adding or subtracting touch panels and my arrays grow and shrink with them. However, in debug I found out that it doesn't actually work. The array gets built by 1 dimention in that cell. :P
Comments
-
ericmedley wrote: »Finally, the secret to my uniform code at last! I can simply keep adding or subtracting touch panels and my arrays grow and shrink with them. However, in debug I found out that it doesn't actually work. The array gets built by 1 dimention in that cell. :P
I always just use a constant such as nMAX_TP to define lengths of variables - and if we add one touch panel I essentially make 2 changes: one to the TP array, the other to the constant that says how big it is. -
I always just use a constant such as nMAX_TP to define lengths of variables - and if we add one touch panel I essentially make 2 changes: one to the TP array, the other to the constant that says how big it is.
... yeah, i know... (* huff *) -
LMAO! C'mon - you can't have everything for nothing!ericmedley wrote: »... yeah, i know... (* huff *)
-
LMAO! C'mon - you can't have everything for nothing!

Here's my goal...PROGRAM_NAME 'Universal Code' DEFINE_DEVICE dv_Everything = 0:0:0 .. 64000:99:255 DEFINE_VARIABLE Persistent_wehn_needed but Volatile_to_save_RAM nc_Var[] DEFINE_START WAIT nLong_Enough { Set_Up_All() } DEFINE_EVENT button_event[dv_Everything,0] { PUSH: { Universal_Function(button.input.device,button.inpu.channel) } } -
Very nice, mind if I use it?
-
If it compiles it must be good, right?ericmedley wrote:volatile AW_TV_POPUP_NAME[length_array(dev_AW_TP_01)][200][40]
And lo and behold, it compiled just fine!
I can?t believe the compiler didn?t freak when you put a function call inside the square brackets of a multidimensional array declaration. I think you took the compiler by surprise and exposed a bug. I sure would like to know what the compiler was thinking when it let that go without barfing.
I didn?t get any semblance of a multidimensional array when I tried it (yeah, I had to try itericmedley wrote:The array gets built by 1 dimention in that cell. :P
). All I got was a one byte null.
Same here.jjames wrote:I always just use a constant such as nMAX_TP to define lengths of variables -
ericmedley wrote: »// and here it is...
volatile AW_TV_POPUP_NAME[length_array(dev_AW_TP_01)][200][40]
[/code]
I do something similar and it seems to work fine. What are the problems you are having?
Paul -
really?
You put a function call inside the square brackets of a multidimensional array declaration and it worked?I do something similar and it seems to work fine.
Can you post an example? I?d love to see what I?ve been missing and then proceed to eat crow.
-
Joe Hebert wrote: »You put a function call inside the square brackets of a multidimensional array declaration and it worked?
Can you post an example? I’d love to see what I’ve been missing and then proceed to eat crow.
I can't find the piece of code I wrote at the moment, but what I think I did was pass an array of TPs to a module, and then in define_start of that module, get the length of the array, and then immediately after that do a set_length_array on the array that is defined in the module using the result from length_array. I don't know what you need this for, but I was using it to make sure an the array declared in the module was the same length of an array that was passed into the module.
Paul -
SET_LENGTH_ARRAY doesn't actually change the size of the memory allocated to said array, it only changes the 'effective' length, i.e. you can make arrays shorter but not longer. Eric I think wanted to -poof- make an array that was only as big as the data it needs to hold, at compile time.I can't find the piece of code I wrote at the moment, but what I think I did was pass an array of TPs to a module, and then in define_start of that module, get the length of the array, and then immediately after that do a set_length_array on the array that is defined in the module using the result from length_array. I don't know what you need this for, but I was using it to make sure an the array declared in the module was the same length of an array that was passed into the module.
Paul -
SET_LENGTH_ARRAY doesn't actually change the size of the memory allocated to said array, it only changes the 'effective' length, i.e. you can make arrays shorter but not longer. Eric I think wanted to -poof- make an array that was only as big as the data it needs to hold, at compile time.
Exactly. For example, the thing that I was doing was a big giant TV control array. I wanted to make it possible to control an enormous number of TVs and any number of TPs without writing any additional code. All I need to do is decalre the TPs and list the TV models and control method and be done.
I honestly didn't know if it would work or not. I just gave it a try and noticed that when I hit compile it went through. It even worked in testing for a short while. However, that was because I was only working on TV#1 and Touch Panel#1. When I tried TV#2, I noticed it wasn't working. That's when I discovered the folly of my ways. -
Sounds perfectly legit to me as those are just a plain old function calls, nothing special or unusual. You can do it in one simple line of code if you want:a_riot42 wrote:I can't find the piece of code I wrote at the moment, but what I think I did was pass an array of TPs to a module, and then in define_start of that module, get the length of the array, and then immediately after that do a set_length_array on the array that is defined in the module.
SET_LENGTH_ARRAY(ModuleArray,LENGTH_ARRAY(dvTPs))
However, that isn’t remotely close to what the original posted code was attempting to do in the declaration. I’ll save the crow for now, I’m sure I’ll need it later.
Edit: And as already pointed out, you can't set the length to a value greater than the original length declared. -
That's the best way to go since you never know what you might stumble into. Experimenting is the fun part.ericmedley wrote: »I honestly didn't know if it would work or not. I just gave it a try
http://science.howstuffworks.com/9-things-invented-or-discovered-by-accident.htm -
So many of these kinds of problems would go away if we only had dynamic memory allocation ...
-
*cough* java *cough*
-
Spire_Jeff wrote: »*cough* java *cough*

Yeah, but I can't get my boss to spring for Cafe Duet. He feels that NetLinx is adequate for programming purposes, and frankly, given the track record with some of the Duet modules, it's not an unjustified position. The bottom line is we won't be migrating to Java any time soon, if at all.
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