Home AMX User Forum AMX Technical Discussion

how to refresh array values inside a module

Hello,

i need to pass an array of integer variables to a module, so if any element of the array is modified outside of the module, the value is refreshed.

For me, the elements of the array, inside the module, maintain the initial value, and i know there is a way to pass the array to the module by reference, not by value.... but can´t remember...

Any help?

Tahnx!

Comments

  • I'm not sure how to do that, but maybe you should tell us the problem you are trying to solve first, and there might be a better/different way to accomplish what you are looking to do. See The X-Y problem.

    Honestly, I don't think there is a way to pass variables to a module by reference, as I believe that modules reference their own memory space and don't have access to the memory where variables for the main code file are referenced. I could be wrong here. You may be thinking of functions, where the parameters are passed by reference, and so you can make changes to a parameter and the variable that was fed into the function changes.

    I'm guessing that the only way to accomplish what you want to do is to create a set of commands in the module that will act as setters/getters for the values you want to change. Alternatively, you could use levels instead, and just have a timeline that sends a level to the module with the correct values for the variables you want to work with.
  • It should work the way MorgoZ expects it to:
    Module parameters behave exactly like subroutine parameters; the parameter list is optional. The value for each parameter is set either by the main program or another module. If the value of a parameter is changed, both the main program and module see the change.

    MorgoZ, can you post the code, or at least a portion of the code, that shows how your array/module is substantiated?
  • DHawthorneDHawthorne Posts: 4,584
    If it's passed entire as a parameter, the original gets changed. If you copy it internally, only the internal values change. So the answer is, make it a module parameter. It will only work for simple variable types (no structures).
Sign In or Register to comment.