Home AMX User Forum NetLinx Studio

And just when I got all excited...

I was goofing around with a new program and tried this:
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

  • jjamesjjames Posts: 2,908
    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.
  • ericmedleyericmedley Posts: 4,177
    jjames wrote: »
    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 *)
  • jjamesjjames Posts: 2,908
    ericmedley wrote: »
    ... yeah, i know... (* huff *)
    LMAO! C'mon - you can't have everything for nothing! :D
  • ericmedleyericmedley Posts: 4,177
    jjames wrote: »
    LMAO! C'mon - you can't have everything for nothing! :D

    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)
      }
    }
    
  • jjamesjjames Posts: 2,908
    Very nice, mind if I use it? ;)
  • Joe HebertJoe Hebert Posts: 2,159
    ericmedley wrote:
    volatile AW_TV_POPUP_NAME[length_array(dev_AW_TP_01)][200][40]
    And lo and behold, it compiled just fine!
    If it compiles it must be good, right? :)

    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.
    ericmedley wrote:
    The array gets built by 1 dimention in that cell. :P
    I didn?t get any semblance of a multidimensional array when I tried it (yeah, I had to try it :) ). All I got was a one byte null.
    jjames wrote:
    I always just use a constant such as nMAX_TP to define lengths of variables
    Same here.
  • a_riot42a_riot42 Posts: 1,624
    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
  • Joe HebertJoe Hebert Posts: 2,159
    really?
    a_riot42 wrote: »
    I do something similar and it seems to work fine.
    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. :)
  • a_riot42a_riot42 Posts: 1,624
    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
  • mpullinmpullin Posts: 949
    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 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.
  • ericmedleyericmedley Posts: 4,177
    mpullin wrote: »
    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.
  • Joe HebertJoe Hebert Posts: 2,159
    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.
    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:
    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.
  • Joe HebertJoe Hebert Posts: 2,159
    ericmedley wrote: »
    I honestly didn't know if it would work or not. I just gave it a try
    That's the best way to go since you never know what you might stumble into. Experimenting is the fun part.

    http://science.howstuffworks.com/9-things-invented-or-discovered-by-accident.htm
  • DHawthorneDHawthorne Posts: 4,584
    So many of these kinds of problems would go away if we only had dynamic memory allocation ...
  • Spire_JeffSpire_Jeff Posts: 1,917
    *cough* java *cough*

    :)
  • DHawthorneDHawthorne Posts: 4,584
    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.
Sign In or Register to comment.