Home AMX User Forum NetLinx Studio
Options

Variable Persistence in Modules

I've just discovered that Persistent variables do not work in Modules. Is this a bug or a "feature", and if the later, why?

Thanks,

--D

Comments

  • Options
    Joe HebertJoe Hebert Posts: 2,159
    Nope, it?s not a bug. If you look up PERSISTANT in the help file you?ll see a note at the bottom which says that you can?t use PERSISTANT variables in MODULEs.

    I don?t know why but whoever does know can perhaps explain why you can?t pass a parameter to a module without creating a variable for it first. If you look up MODULE in the help file it states - Constants and expressions cannot be used as arguments in the parameter list. Why not? I never understood that one.
  • Options
    My bets:

    You cannot use persistent in modules because of the memory organization. I think modules are loaded after main code is, and persistent is performed at the very beginning.

    You cannot use constant in modules because there is no mechanism in the module system to forward INSIDE the module the information that the parameter is a constant. You can modify the variable from both sides (inside and outside). So if you use a constant from the outside, it could be modified inside the module (in principle).

    Fred
  • Options
    DHawthorneDHawthorne Posts: 4,584
    You can pass a persistent variable to a module as a parameter, then just declare it as persistent in your main code.
  • Options
    Write any persistant variables to flash whenever the value changes and reload with the online event of the master or a virtual device
Sign In or Register to comment.