Persistent variable  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
darrepac
Posts: 142
Joined: Tuesday 04 February 2014 21:31
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Isère, France
Contact:

Persistent variable

Post 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
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Persistent variable

Post 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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
darrepac
Posts: 142
Joined: Tuesday 04 February 2014 21:31
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Isère, France
Contact:

Re: Persistent variable  [Solved]

Post by darrepac »

Thanks for the detailed information!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest