Page 1 of 1

Unable to update a user variable

Posted: Friday 25 December 2020 19:06
by duodiscu92
Hi everyone,
Below is a part of my script_device code in lua where b1 and b2 are user variables
I can easily read them but I cannot change them

Code: Select all

...
b1 = 'Batterie1'
b2 = 'Batterie2'

------------------------------------------------------------------------------
commandArray = {}

if (devicechanged[actb1]) then
  print("B1 : " .. tostring(devicechanged[actb1]) .. " User VarB1 = " .. uservariables[b1])
  if( (tostring(devicechanged[actb1]) == "EN SERVICE") and (uservariables[b1] == 0) ) then
    print ("En service et B1 == 0")
    commandArray['Variable:b1'] = '1'
...
The line

Code: Select all

commandArray['Variable:b1'] = '1'
seems to be without effect

An idea ?
Thanks for your help

Re: Unable to update a user variable

Posted: Friday 25 December 2020 20:17
by sieth
if b1 is a string


if( (tostring(devicechanged[actb1]) == "EN SERVICE") and (uservariables[b1] == 0) ) then
print ("En service et B1 == 0")
commandArray[#commandArray+1]={['Variable:b1'] = tostring ('1')}


or if 1b is an integer:
if( (tostring(devicechanged[actb1]) == "EN SERVICE") and (uservariables[b1] == 0) ) then
print ("En service et B1 == 0")
commandArray[#commandArray+1]={['Variable:b1'] = 1}

Re: Unable to update a user variable

Posted: Friday 25 December 2020 21:00
by duodiscu92
Thank you Sieth but I have found just now :

Code: Select all

commandArray['Variable:b1'] = '1'
is not allowed, because b1 is not replaced by its value which is "Batterie1"

So the good writing is :

Code: Select all

commandArray['Variable:Batterie1'] = '1'
and then it works well.