Home AMX User Forum AMX General Discussion

Variable through a module?

I am trying to pass a variable into a function. In the mainline I have:
CHAR myNewVariable[] = '5000';

Then I have my module included:
DEFINE_MODULE 'MyModule' MyMod(myNewVariable[])

My module signature:
MODULE_NAME ='MyModule' (theVariable[])


However, if in the code I do something like:
theVariable = '10000';

The mainline variable doesn't get updated. Shouldn't it?


And the module variable doesn't seem to reflect what the mainline variable is, either. What am I doing wrong?

Thanks,
Dan

Comments

  • jjamesjjames Posts: 2,908
    In instances like these, you'd be better off associating the variable with LEVEL or a COMMAND.

    For instance:
    DEFINE_DEVICE
    vdvVirtual= 34001:01:0
    
    SEND_LEVEL vdvVirtual, 1, myNewVariable
    
    //or 
    
    SEND_COMMAND vdvVirtual, "'VARIABLE = ', ITOA(myNewVariable)"
    

    And then have a LEVEL_EVENT in the module or create a COMMAND event.

    Good luck!
  • Spire_JeffSpire_Jeff Posts: 1,917
    dmurray14 wrote: »
    I am trying to pass a variable into a function. In the mainline I have:
    CHAR myNewVariable[] = '5000';
    
    Change to this: 
    CHAR myNewVariable[10] = '5000';
    

    Then I have my module included:
    DEFINE_MODULE 'MyModule' MyMod(myNewVariable[])
    

    My module signature:
    MODULE_NAME ='MyModule' (theVariable[])
    
    change this to:
    MODULE_NAME ='MyModule' (Char theVariable[])
    

    However, if in the code I do something like:
    theVariable = '10000';
    

    The mainline variable doesn't get updated. Shouldn't it?


    And the module variable doesn't seem to reflect what the mainline variable is, either. What am I doing wrong?

    Thanks,
    Dan

    Try that and it should work. I have passed variables and them seem to update with no problems. If this still doesn't work, let me know and I will research it a little further as this could affect some of my modules.

    Jeff
  • viningvining Posts: 4,368
    dmurray14 wrote:
    My module signature:
    
    Code:
    MODULE_NAME ='MyModule' (theVariable[])
    
    You need to declare your variable type. Since it isn't delcared as a CHAR array it thinks it's INTEGER array. If it was an integer in your main that would probably be fine but you shoud get in the habit declaring them just for clarity sake.
    MODULE_NAME ='MyModule' (CHAR theVariable[])
    

    It's not Vegas so what happens in the module doesn't stay in the module and changes should be reflected in your main code.

    Edit..

    You also don't need the braces after the var array in your module declaration.
    Then I have my module included:
    
    
    Code:
    DEFINE_MODULE 'MyModule' MyMod(myNewVariable[])
    
    
    DEFINE_MODULE 'MyModule' MyMod(myNewVariable)
    
    I don't know if it hurts but it isn't required. I would think it wouldn't compile w/ them but I guess it does. They are required in your module header though because there your declaring the variable type!
  • dmurray14dmurray14 Posts: 80
    Thanks guys! As usual, you are all so helpful...
Sign In or Register to comment.