Home AMX User Forum NetLinx Studio

Compiler Error C10583: Too many elements in initializer

Hey Gents,

I haven't programmed AMX in quite a while and I'm currently running into an issue while using a structure and an array following that.
DEFINE_TYPE
STRUCTURE LIGHT_LEVEL_SLIDERS{
    integer slider_number;
    char    address[3];
    integer value;
}

DEFINE_VARIABLE
light_level_sliders light_level_slider[60]={
    {1 ,'000',0},{2 ,'000',0},{3 ,'000',0},{4 ,'000',0},
    {5 ,'000',0},{6 ,'000',0},{7 ,'000',0},{8 ,'000',0},
    {9 ,'000',0},{10,'000',0},{11,'485',0},{12,'486',0},
    {13,'487',0},{14,'488',0},{15,'513',0},{16,'000',0},
    {17,'000',0},{18,'000',0},{19,'000',0},{20,'000',0},
    {21,'411',0},{22,'427',0},{23,'428',0},{24,'429',0},
    {25,'000',0},{26,'000',0},{27,'000',0},{28,'000',0},
    {29,'000',0},{30,'000',0},{31,'563',0},{32,'567',0},
    {33,'000',0},{34,'000',0},{35,'000',0},{36,'000',0},
    {37,'000',0},{38,'000',0},{39,'000',0},{40,'000',0},
    {41,'531',0},{42,'530',0},{43,'529',0},{44,'532',0},
    {45,'541',0},{46,'913',0},{47,'915',0},{48,'907',0},
    {49,'911',0},{50,'827',0},{51,'917',0},{52,'919',0}
}

What I get back from the compiler:
---------- Starting NetLinx Compile - Version[2.5.2.420] [05-12-2015 11:48:38] ----------  
C:\test.axs  
WARNING: C:\test.axs(78): C10571: Converting type [string] to [CHAR]  
ERROR: C:\test.axs(77): C10583: Too many elements in initializer  
C:\test.axs - 1 error(s), 1 warning(s)  
NetLinx Compile Complete [05-12-2015 11:48:39]  

I'm not sure what is causing the error, I guess I'm initializing it in the wrong way? I can't find an example in the help files other than initializing it on a per value basis. I'm afraid that's the only way, so I hope you can provide a better way to initialize the values.

Comments

  • Ma_ZeMa_Ze Posts: 5
    Jorde_V wrote: »
    Hey Gents,

    I haven't programmed AMX in quite a while and I'm currently running into an issue while using a structure and an array following that.
    DEFINE_TYPE
    STRUCTURE LIGHT_LEVEL_SLIDERS{
    integer slider_number;
    char address[3];
    integer value;
    }
    
    DEFINE_VARIABLE
    light_level_sliders light_level_slider[60]={
    {1 ,'000',0},{2 ,'000',0},{3 ,'000',0},{4 ,'000',0},
    {5 ,'000',0},{6 ,'000',0},{7 ,'000',0},{8 ,'000',0},
    {9 ,'000',0},{10,'000',0},{11,'485',0},{12,'486',0},
    {13,'487',0},{14,'488',0},{15,'513',0},{16,'000',0},
    {17,'000',0},{18,'000',0},{19,'000',0},{20,'000',0},
    {21,'411',0},{22,'427',0},{23,'428',0},{24,'429',0},
    {25,'000',0},{26,'000',0},{27,'000',0},{28,'000',0},
    {29,'000',0},{30,'000',0},{31,'563',0},{32,'567',0},
    {33,'000',0},{34,'000',0},{35,'000',0},{36,'000',0},
    {37,'000',0},{38,'000',0},{39,'000',0},{40,'000',0},
    {41,'531',0},{42,'530',0},{43,'529',0},{44,'532',0},
    {45,'541',0},{46,'913',0},{47,'915',0},{48,'907',0},
    {49,'911',0},{50,'827',0},{51,'917',0},{52,'919',0}
    }
    

    What I get back from the compiler:
    ---------- Starting NetLinx Compile - Version[2.5.2.420] [05-12-2015 11:48:38] ----------
    C:\test.axs
    WARNING: C:\test.axs(78): C10571: Converting type [string] to [CHAR]
    ERROR: C:\test.axs(77): C10583: Too many elements in initializer
    C:\test.axs - 1 error(s), 1 warning(s)
    NetLinx Compile Complete [05-12-2015 11:48:39]
    

    I'm not sure what is causing the error, I guess I'm initializing it in the wrong way? I can't find an example in the help files other than initializing it on a per value basis. I'm afraid that's the only way, so I hope you can provide a better way to initialize the values.

    Hello.

    I`d do this another way:
    DEFINE_TYPE
    STRUCTURE LIGHT_LEVEL_SLIDERS{
        integer slider_number;
        char    address[3];
        integer value;
    }
    
    DEFINE_VARIABLE
    light_level_sliders light_level_slider[60]
    
    And then maybe some subroutine to init those values:
    DEFINE_CALL 'Init'
    {
        light_level_slider[1].slider_number = 1
        light_level_slider[1].address = '000'
        light_level_slider[1].value = 0
        
        light_level_slider[2].slider_number = 2
        light_level_slider[2].address = '000'
        light_level_slider[2].value = 0
    
    etc....
    }
    

    Don`t know if it`s best way but i guess it`ll do the job.

    M.
  • Jorde_VJorde_V Posts: 393
    Ma_Ze wrote: »

    Hello.

    I`d do this another way:
    DEFINE_TYPE
    STRUCTURE LIGHT_LEVEL_SLIDERS{
    integer slider_number;
    char address[3];
    integer value;
    }
    
    DEFINE_VARIABLE
    light_level_sliders light_level_slider[60]
    
    And then maybe some subroutine to init those values:
    DEFINE_CALL 'Init'
    {
    light_level_slider[1].slider_number = 1
    light_level_slider[1].address = '000'
    light_level_slider[1].value = 0
    
    light_level_slider[2].slider_number = 2
    light_level_slider[2].address = '000'
    light_level_slider[2].value = 0
    
    etc....
    }
    

    Don`t know if it`s best way but i guess it`ll do the job.

    M.

    I'm doing that in the startup code of the virtual device right now, but I was hoping it could be done in a way similar as I'm trying above.
  • PhreaKPhreaK Posts: 966
    With the exception of the define_call (I use define_function) Ma_Ze's approach is the same I use.

    In each source code file, weather that be a axs or axi, I'll initialise any of my globals that instantiate user defined types. The syntax you're trying to use above is AFAIK limited to the 'dev' structure.
  • Jorde_VJorde_V Posts: 393
    PhreaK wrote: »
    With the exception of the define_call (I use define_function) Ma_Ze's approach is the same I use.

    In each source code file, weather that be a axs or axi, I'll initialise any of my globals that instantiate user defined types. The syntax you're trying to use above is AFAIK limited to the 'dev' structure.


    That's a shame, really hoped they would've implemented it for this as well.
  • Ma_ZeMa_Ze Posts: 5
    PhreaK wrote: »
    With the exception of the define_call (I use define_function) Ma_Ze's approach is the same I use.

    Just wondering, is there any particular reason to use define_function there? What does it return?

  • ericmedleyericmedley Posts: 4,177
    Ha! this is one of my pet peeves about Netlinx. I've always found it funny how the way which one declares a constant and the way one declares a variable with starting values is in many cases a different format. I oft find myself doing all these kinds of trial-and-error methods to get stuff to work.
  • Jorde_VJorde_V Posts: 393
    ericmedley wrote: »
    Ha! this is one of my pet peeves about Netlinx. I've always found it funny how the way which one declares a constant and the way one declares a variable with starting values is in many cases a different format. I oft find myself doing all these kinds of trial-and-error methods to get stuff to work.

    Same here, I do most by trial and error. Mostly because some things don't work the way i expect nor the way the help file implies
  • PhreaKPhreaK Posts: 966
    Ma_Ze wrote: »

    Just wondering, is there any particular reason to use define_function there? What does it return?
    define_call is a legacy language item still there from access days. You don't need to return anything from a function (just omit the return data type in the declaration), however using it for all subroutines whether they return a value or not keeps your calling syntax the same.
  • ericmedleyericmedley Posts: 4,177
    Ma_Ze wrote: »

    Just wondering, is there any particular reason to use define_function there? What does it return?



    The stated reason/thinking is: Use a function when yo want a return from the thing (a result)
    Use a Call when you just have a routine to run and don't need a value coming back.

    I've asked if there is any performance hit by using a function with no return value vs. using a Call. the engineer wasn't sure. I've never really benchmarked the results myself.

    I almost never use Calls as I find them clunky to type. Functions are nice in that I name all mine prefixed with "fn_" as in "fn_MyAwesome_Function()"

    I like that they act like keywords in that i just start typing "fn_" and a popup menu of all my functions appears.

    I may at some time (if I ever have time) run a benchmark test to see if functions or calls work better process-wise.
  • chillchill Posts: 186
    I do just that: functions return something, calls do not. To me, their clunkiness values are equal. I would be astonished if there were a noticeable performance difference.

    Of course you can write a function that doesn't return a value; it just offends my sensibilities. It's a personal preference thing, sort of like "toCamelCase or not to camel case". I don't use autocomplete either, because too often it doesn't Do The Right Thing for me.

    And while define_call is certainly an Axcess legacy, that seems irrelevant. The fact that a thing existed before 1999 is not a reason to stop using it. See TV, cars, DEFINE_START...
    .
  • PhreaKPhreaK Posts: 966
    chill wrote: »
    See TV, cars, DEFINE_START...
    Nobody buys a 'TV' anymore - you get a nice display with a computer inside and an internet connection (see Netflix), pre 1999 cars are all pieces of crap compared to something a little more modern (see Tesla) and the online event of dev 0:1:0 / the device that section of code is related to is nicer than define_start :p
  • Jorde_VJorde_V Posts: 393
    PhreaK wrote: »
    Nobody buys a 'TV' anymore - you get a nice display with a computer inside and an internet connection (see Netflix), pre 1999 cars are all pieces of crap compared to something a little more modern (see Tesla) and the online event of dev 0:1:0 / the device that section of code is related to is nicer than define_start :p


    I thought I also read that DEFINE_START shouldn't be used with the NX series anymore. (Same as DEFINE_PROGRAM, but I haven't used that in years anyway)

    On a side-note I think it's better to use functions because of the way they work and the syntax is comparable to a lot of other languages, whereas Calls aren't really used. Normally you would use a function and return success or an error code, for simple installations I guess this might seem as overkill. For larger installs however it's a must-have in my opinion. Compiler directives such as #IF_DEFINED are your friends in many cases. (I use this for running test code that I don't want to run in the main program)
  • ericmedleyericmedley Posts: 4,177
    Yeah, I think we may be "counting how many angels can dance on the head of a pin" here. there's noting really magical about functions or calls. After all, they are really just both frameworks for the compiler to create branchable code; a section of code to occasionally run to and leave. The processor overhead to maintain them is probably along the lines of similar, if not exactly the same.
  • DHawthorneDHawthorne Posts: 4,584
    Jorde_V wrote: »


    I thought I also read that DEFINE_START shouldn't be used with the NX series anymore. (Same as DEFINE_PROGRAM, but I haven't used that in years anyway)

    On a side-note I think it's better to use functions because of the way they work and the syntax is comparable to a lot of other languages, whereas Calls aren't really used. Normally you would use a function and return success or an error code, for simple installations I guess this might seem as overkill. For larger installs however it's a must-have in my opinion. Compiler directives such as #IF_DEFINED are your friends in many cases. (I use this for running test code that I don't want to run in the main program)

    DEFINE_START is still required. Take it out, and your project won't compile at all. Technically, all your DEFINE_FUNCTION and DEFINE_MODULE blocks are part of DEFINE _START. You don't want to initialize devices in there anymore, like in the Axcess days, but there are times when you need to populate a structure, or something similar. It's still appropriate for that as well.
  • GregGGregG Posts: 251
    I have definitely compiled and loaded programs that do not include a DEFINE_START section.
  • ericmedleyericmedley Posts: 4,177
    DHawthorne wrote: »

    DEFINE_START is still required. Take it out, and your project won't compile at all. Technically, all your DEFINE_FUNCTION and DEFINE_MODULE blocks are part of DEFINE _START. You don't want to initialize devices in there anymore, like in the Axcess days, but there are times when you need to populate a structure, or something similar. It's still appropriate for that as well.

    is this true??? I have many projects without define_start that compile. they also don't have define_program. They have all the other stuff. granted I'm using NS4.
  • PhreaKPhreaK Posts: 966
    Ditto here. I'm fairly sure the compiler with NS3 never complained either.
  • Jorde_VJorde_V Posts: 393
    DHawthorne wrote: »

    DEFINE_START is still required. Take it out, and your project won't compile at all. Technically, all your DEFINE_FUNCTION and DEFINE_MODULE blocks are part of DEFINE _START. You don't want to initialize devices in there anymore, like in the Axcess days, but there are times when you need to populate a structure, or something similar. It's still appropriate for that as well.


    Like the guys above experienced, there is no need for a DEFINE_START section. I haven't used it, nor have I used a DEFINE_PROGRAM for example. All you need to compile is
    PROGRAM_NAME=''
    
    

    You can add functions etc without a DEFINE_START, nothing is required for the compiler.

    For example:
    PROGRAM_NAME=''
    
    DEFINE_FUNCTION Check(){
        ;
    }
    
    DEFINE_EVENT
    BUTTON_EVENT[10001:1:0,0]{
        PUSH:{;}
    }
    

    This compiles just fine.
Sign In or Register to comment.