Home AMX User Forum AMX General Discussion
Options

Question on passing Modules, Constants and Persistent Vars

Regarding Persistent Vars not working with modules. The compiler allows persistent vars to be passed to a module. Does this mean that the persistent vars passed will not be accesible by the module? or maybe persistent vars work with modules, but can't be declared inside the body of a module.

Does anyone know the answer to the above question?

Comments

  • Options
    Yes, you are right. Persistent variables do not work in a module. There are two ways to solve this....

    1) Declare a presistent variable in your main program and pass it as a parameter to your module.
    2) Save and load the variable to the Disc On Chip. The code to do this should be inside the module. What I mostly do is, create a filename based on the virtual device number and the variable name. So when you use multiple instances of the same module the file name is different for each module.

    Hope this helps.
  • Options
    frthomasfrthomas Posts: 176
    Re: Question on Modules and Persistent Vars
    Originally posted by AlexArtist
    Regarding Persistent Vars not working with modules. The compiler allows persistent vars to be passed to a module. Does this mean that the persistent vars passed will not be accesible by the module?

    No, that works and is solution 1) in Leon's anser.
    or maybe persistent vars work with modules, but can't be declared inside the body of a module.

    Exactly.
    Originally posted by Leon ten Brundel
    Yes, you are right. Persistent variables do not work in a module.

    To be a little bit more specific: Persistent variables can be declared in a module however they are not persistent. IMHO the compiler should flag this, but it doesnt.

    Fred
  • Options
    Yes, Fred you are right. You did not even get an warning when you compile the module. It would be nice if this persistent behaviour of a variable would be fixed in future releases. I don't understand why it can not work. Each instance of a module could be 'name mangeling' the variable with the instance name used for the module. So I think it should be feasible for AMX to fix this. But maybe there are some other issues that we all are not aware of.
  • Options
    DHawthorneDHawthorne Posts: 4,584
    Originally posted by Leon ten Brundel
    Yes, Fred you are right. You did not even get an warning when you compile the module. It would be nice if this persistent behaviour of a variable would be fixed in future releases. I don't understand why it can not work. Each instance of a module could be 'name mangeling' the variable with the instance name used for the module. So I think it should be feasible for AMX to fix this. But maybe there are some other issues that we all are not aware of.
    Persistent varibles are restored on start up before module allocation occurs. The system doesn't even know to check for them until it's too late.
Sign In or Register to comment.