Hi geeks !
I would like display in my game this message for some tests :
|test : true|
but "test" is a boolean variable. I can display with a classical variable with :
but with a boolean variable no :
I have an error :
line 106: attempt to concatenate local 'test' (a boolean value)
Thank in advance for your help :)
you can put anything in print() as long as it evaluates to a printable value.
- (a and b) returns a if a is false or nil, b otherwise (whatever b is)
- (a or b) returns b if a is false or nil (whatever b is), a otherwise (whatever a is)
- operator and has precedence over operator or
so here's how the evaluation goes:
(true and '1' or '0') -> ((true and '1') or '0') -> '1' or '0' ->'1'
(false and '1' or '0') -> ((false and '1') or '0') -> false or '0' ->'0'
this syntax (a and b or c) is the lua version of the conditional ternary operator (3 operands).
that's very handy once you know it :)
[Please log in to post a comment]