Home AMX User Forum NetLinx Studio

Error.... Initializer is not a Constant ???

Greetings,

I am creating a DEV array within a module of six devices that are defined in the main program. The devices are carried into the module in the DEFINE_MODULE of the program and the MODULE_NAME of the module.

Upon compilation of the module, I get the message that Initializer is not a constant, referring to the line where I create the DEV of the six devices.

I am just getting into module writing and would appreciate any suggestions.

Thanks.

Comments

  • GSLogicGSLogic Posts: 562
    Try moving your DEFINE_MODULE in the DEFINE_VARIABLE section in the main.axs file.
  • viningvining Posts: 4,368
    Why don't you declare the dev array in your main and just pass the whole thing to your module?
  • TurnipTruckTurnipTruck Posts: 1,485
    vining wrote:
    Why don't you declare the dev array in your main and just pass the whole thing to your module?
    That is what I did. It was a confusing road at first, but I got there.

    Thanks.
  • DHawthorneDHawthorne Posts: 4,584
    The reason for the error is that when you initialize a variable inside a module, the compiler has to know what the value is beforehand. Variables passed to a module don't have a value at the time of the module initialization because the modules are compiled before the main program (in fact, they are compiled independent of the main program in most cases). So, in effect, you are trying to initialize your array with values that don't exist yet as far as the compiler can see.

    Passing the entire array works because you aren't initializing it within the module anymore, you are simply allocating the memory space. It gets populated at runtime (when it applies the parameters to the instance) instead of compile time. You could also accomplish the same thing by populating your array in DEFINE_START of the module.
Sign In or Register to comment.