This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Script - how to end script if true
#1
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
Reply
#2
You can do this on a few ways.

1) You can return before second if

Code:
12345678
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:
12345678
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:
123
if temp1 < temp2 and temp3 < temp4 then   -- do something end
Done is better than perfect
Reply
#3
Thanks  Smile Nest of the second if was a great solution for my case.
Reply
#4
I think now you will write more powerful programsWink
Done is better than perfect
Reply


Forum Jump: