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.

My lua script is not return the result that I want
#1
I want to set v = false if condition true or otherwise v = nil. I use this code:

Code:
value = 4>3 and false or nil

or

Code:
value = 3<4 and false or nil

The result always nil. Do you know why it's not work? How could I fix it. I want to write in shortway so I dont want to use if conditon.

Well I ask google gemini and get the answer. thanks.
Reply
#2
Maybe try "if then else" construction?
If indeed object can have nil value...
Reply
#3
value = 4>3 and false or nil
value = 4<3 and false or nil

you always get NIL because result of the first expression ([ANY] AND FALSE) is always FALSE by definition (because you have FALSE as one of the operands in AND construct)

if you want to use this construct, you can use number 0 instead of boolean value.
Reply
#4
(27.03.2025, 09:25)myg Wrote: value = 4>3 and false or nil
value = 4<3 and false or nil

you always get NIL because result of the first expression ([ANY] AND FALSE) is always FALSE by definition (because you have FALSE as one of the operands in AND construct)

if you want to use this construct, you can use number 0 instead of boolean value.

It's nice. thank you
Reply


Forum Jump: