Logic Machine Forum
Script - how to end script if true - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Script - how to end script if true (/showthread.php?tid=1685)



Script - how to end script if true - Kai-Roger - 31.10.2018

Hi.

I have some code that i want to stop/exit at first line if true. How is this achived in Lua? I can't find a straight answer for this on google.


if VALUE1 < VALUE2 then "don't go to next if: exit, break, return or something like that"
end
if VALUE3 < VALUE4 then do something
end


RE: Script - how to end script if true - buuuudzik - 01.11.2018

You can do this on a few ways.

1) You can return before second if

Code:
if temp1 < temp2 then
  -- do something
  return -- could be with some value
end

if temp3 < temp4 then
 -- do something
end


2) You can nest your second if in the first

Code:
if temp1 < temp2 then
-- do something

 if temp3 < temp4 then
   -- do something
 end

end

3) If in the first if there is only this secondd you can combine your conditions with AND gate

Code:
if temp1 < temp2 and temp3 < temp4 then
  -- do something
end



RE: Script - how to end script if true - Kai-Roger - 01.11.2018

Thanks  Smile Nest of the second if was a great solution for my case.


RE: Script - how to end script if true - buuuudzik - 01.11.2018

I think now you will write more powerful programsWink