Boolean syntax for conditional?

I cannot make this work:

[code]
local flag = true

if flag then

end
[/code]

I know there is a way to make that work without doing:

<br>if flag == true then<br> <something><br>end<br>

I swallow my pride and ask for help on something SIMPLE like this… help me!! What’s the right syntax? The WOW Lua scripters say you can do what I show up top and it works, but I cannot make that syntax work in Corona.

Thanks in advance. [import]uid: 74844 topic_id: 13713 reply_id: 313713[/import]

Works fine for me.

-- bool test  
local flag = true;  
  
if flag then  
 print("true");  
else  
 print("false");  
end  
  
if not flag then  
 print("true");  
else  
 print("false");  
end  
  
if (flag == true) then  
 print("true");  
else  
 print("false");  
end  
  
if (not flag == true) then  
 print("true");  
else  
 print("false");  
end  
  
--[[ outputs  
true  
false  
true  
false  
--]]  

[import]uid: 238 topic_id: 13713 reply_id: 50364[/import]

lua has a not equal operator, so you can do if flag ~= true then

I tend to use if var then and if not var then

The thing to remember here though is lua is not a typed language if foo then will be true if foo is true or non nil, similarly if not foo then will be true if foo is false or nil. [import]uid: 68937 topic_id: 13713 reply_id: 50384[/import]

Hmmm, I don’t know why I wasn’t meeting with success before…but it’s working fine now. I dunno. (Thank you!)

@MatthewJHanlon: Understood. If var is set to nil, what you describe is what I would expect. [import]uid: 74844 topic_id: 13713 reply_id: 50409[/import]