Page 1 of 1

Persistent variable

Posted: Sunday 25 August 2019 12:18
by darrepac
Hi

I am starting to persistent variable. I have a strange behaviour in my opinion.
I initialize a variable called temp to let's say 20.
The variable is well kept between different call to the script. Perfect.

But it happens that my script is not working as expected, so I make change in the script and save it again. In my opinion, the script, when saved, should re-initialize the variable, because you have changed something in the script and it doesn't make sense to keep previous values of variables.
It doesn't behave like this. Is it a feature or it is something that should be changed?

thanks

Re: Persistent variable

Posted: Sunday 25 August 2019 18:32
by waaren
darrepac wrote: Sunday 25 August 2019 12:18 I initialize a variable called temp to let's say 20.
The variable is well kept between different call to the script.
But it happens that my script is not working as expected, so I make change in the script and save it again. In my opinion, the script, when saved, should re-initialize the variable, because you have changed something in the script and it doesn't make sense to keep previous values of variables.
It doesn't behave like this. Is it a feature or it is something that should be changed?
It is definitely a feature.
dzVents does not have a clue what has been changed in the script. It might just be a typo in a log statement that you corrected. Some of the persistent variables can be quite complex like tables with lots of valuable information for the user or a persistent history variable that you want to keep eternally. So that is why dzVents does not re-initialize the variable when not explicitly asked using the initialize or reset functions.
Other methods to start over again with persistent variables is to manually throw away the data file
(<domoticz dir>/scripts/dzVents/data/__data_<scriptname>.lua)
containing the vars (dzVents will recreate it the next time the script is triggered)
or
rename your edited script to include a version number e.q. dzVentsScript 032 (persistent) .lua
A new datafile with fresh persistent vars will be created.

Re: Persistent variable  [Solved]

Posted: Sunday 25 August 2019 18:39
by darrepac
Thanks for the detailed information!