Global or local variable
Posted: Tuesday 16 November 2021 16:27
Standard is a variable a global variable. But when I call a variable in a "If then" Statement the variable is NIL. Outside the actual "If then" statement I declare the variable x.
How to use a variable in the whole program and not only in the "If then"statement?.
example to determine the variable x
Error code in log: Error: EventSystem: in test-lua: [string "commandArray = {}..."]:12: attempt to concatenate a nil value (global 'x')
Thx
How to use a variable in the whole program and not only in the "If then"statement?.
example to determine the variable x
Code: Select all
commandArray = {}
if (devicechanged['RemoteWK2'] == "Off") then
print(' Switch is Off')
x = 1
print(' X = : ' .. x .. ' ');
end
if (devicechanged['RemoteWK2'] == "On") then
print('Switch is On')
print(' X = : ' .. x .. ' ');
end
print(x)
return commandArray
Thx