Page 1 of 1
Lua using old variable value
Posted: Thursday 02 August 2018 22:33
by rednas
Hello,
I am using a Lua script to check a variable with a date and a time.
If the date and time have passed, it runs a script and empties the variable.
However, I am printing the variable value and it still uses the old value with the date and time (shown in the log) and if I look at the variables page it shows up emtpy.
Does someone know what's happening?
Thanks!
Re: Lua using old variable value
Posted: Thursday 02 August 2018 22:49
by jvdz
When/how do you print it? Within the same script you put in the CommandArray entry?
Jos
Re: Lua using old variable value
Posted: Thursday 02 August 2018 22:58
by waaren
rednas wrote: ↑Thursday 02 August 2018 22:33
Hello,
I am using a Lua script to check a variable with a date and a time.
If the date and time have passed, it runs a script and empties the variable.
However, I am printing the variable value and it still uses the old value with the date and time (shown in the log) and if I look at the variables page it shows up emtpy.
Does someone know what's happening?
Thanks!
To be certain we will have to see your relevant script(s) but my guess in this case is that you print the content of the var before the
line. If that is how your code looks like the change of the variable simply did not happen yet as domoticz only act on the commands in the commandArray when it received the array back from your Lua
Re: Lua using old variable value
Posted: Friday 03 August 2018 8:05
by rednas
The script runs every minute and I print the value before "return commandArray" because I want to know what the value is before changing it offcourse.
However, the next time the script runs (when the value should be empty and it is empty in my variable tab in domoticz) it still shows the old value..
Re: Lua using old variable value
Posted: Friday 03 August 2018 8:41
by waaren
rednas wrote: ↑Friday 03 August 2018 8:05
The script runs every minute and I print the value before "return commandArray" because I want to know what the value is before changing it offcourse.
However, the next time the script runs (when the value should be empty and it is empty in my variable tab in domoticz) it still shows the old value..
Again; showing the script would help..
Re: Lua using old variable value
Posted: Friday 03 August 2018 9:12
by rednas
Already got it to work. Looks like Domoticz doesn't like empty strings as variables or I am doing something wrong. However, I now changed the script to change the variable to a dash "-" instead of an empty string.
Now the script works like a charm!
Re: Lua using old variable value
Posted: Friday 03 August 2018 9:20
by jvdz
I think your issues is simply:
You do something like:
Code: Select all
commandArray = {}
commandArray['Variable:Test']='1'
print(uservariables["Test"])
return commandArray
That will not work as the commands you put in commandArray are handed back to the event system at the script end and will then be performed by the event system, not during execution of the script!
Jos
Re: Lua using old variable value
Posted: Friday 03 August 2018 9:41
by rednas
No, that is not the case.
I am printing the ORIGINAL value and I am never printing the value I change it to.
It does work with updating my variable to a dash "-" instead of changing it to empty "".
So, it has nothing to do with the printing of the value, but with the value of the variable.