[quote=“Bulldoglowell, post:2, topic:180393”]you have it, really. If-then statements are as straightforward as they are written
With Vera, you are trying to test for True (Let the scene run) or False (cancel the scene).
(comments in Lua are preceded with ‘–’ and Lua ignores comments after these and before a carriage return, and my comments are in the code)
local status1 = luup.variable_get("urn:upnp-org:serviceId:VSwitch1","Status",67) --you will see Lua programmers define variables in the 'local' routine versus global
local status2 = luup.variable_get("urn:upnp-org:serviceId:VSwitch1","Status",68)
if (tonumber(status1) == 1) OR (tonumber(status2) == 1) -- you are testing here to see if either switch is ON **see note
then -- the then statement tells Lua what to do if 'if' is true
return false -- cancels scene and stops the Lua
end -- ends this part of the program and the program proceeds to the next part
return true -- while the default return in vera's Lua is true, good programming includes this to set the variable in clean code, many of us will leave this out.
Does that help?
**Note
Lua does a great job of coercion of variables into integers and numbers so you may see [if (tonumber(status1) == 1)] written by some programmers as [if status1 ==1] so don’t get confused. Lua is pretty smart like that and will automatically convert string and number types to the correct format in order to perform calculations.[/quote]
Thx.
But i don’t get it to work…
I used the following lua:
local Status1 = luup.variable_get("urn:upnp-org:serviceId:VSwitch1","Status",53)
local Status2 = luup.variable_get("urn:upnp-org:serviceId:VSwitch1","Status",68)
if (tonumber(Status1) == 1) OR (tonumber(Status2) == 1)
then
return false
end
return true
When i save it vera reports:
Error: error in lua for scenes and events
I really don’t see what is wrong here?
Is there somewhere an option where it is listed in which scene and lua line the error is?
When i comment out some parts the error is gone:
local Status1 = luup.variable_get("urn:upnp-org:serviceId:VSwitch1","Status",53)
--local Status2 = luup.variable_get("urn:upnp-org:serviceId:VSwitch1","Status",68)
if (tonumber(Status1) == 1) -- OR (tonumber(Status2) == 1)
then
return false
end
return true
the above code give no lua error anymore, so i am pretty sure the error is somewhere in my lua code in this scene, buit i dont see it…
edit:
it seems that the command OR is not reqonized in lua, when i change OR into AND the lua works, but with the wrong effect…
I need and OR statement, not an AND statement…
Can someone advise how to fix this?