Logic Machine Forum
My lua script is not return the result that I want - 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: My lua script is not return the result that I want (/showthread.php?tid=5948)



My lua script is not return the result that I want - pouralise - 26.03.2025

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.


RE: My lua script is not return the result that I want - djaval - 27.03.2025

Maybe try "if then else" construction?
If indeed object can have nil value...


RE: My lua script is not return the result that I want - myg - 27.03.2025

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.


RE: My lua script is not return the result that I want - pouralise - 28.03.2025

(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