Please look at the below Lua script.
Idea is, before changing the status, am getting the current status by calling "getStateFlag()" and assigning to "status" variable. Methods ChangeState1 or ChangeState2 can change the current status. So later when calling ResetStatus method I can reset to old status by assigning stored value of "status".
But issue is, this "status" variable always sets to 0.
function Start()
status = 0
local flag = getStateFlag()
if(flag == 1) then
status = getCurrentStatus()
ChangeState1()
else if(flag == 2) then
status = getCurrentStatus()
ChangeState2()
else
ResetStatus(status)
end
end
function ChangeStatus1()
device::set_value(1)
end
function ChangeStatus1()
device::set_value(2)
end
function ResetStatus(status)
device::set_value(status)
end