I’m new to Lua but not to game coding… how do you the pseudo code below
IF condition A == TRUE OR condition A == TRUE then …
eg.
if gameTimer == 0 OR gameLives == 0 then
gameMode = “GAMEOVER” --code to show game is now over
else
–continue with game code --game not over so continue
end
up till now I have structured my code to get around this but now I either need to duplicate a large block of code or use a function and try to sort out which varibles can stay local or need to become global. all quite messy and unnecessary… if someone can show how you can set up multiple condition testing… many thanks
[import]uid: 3093 topic_id: 9812 reply_id: 309812[/import]
I’m not sure what you’re asking about; are you simply wondering if Lua has an “or” keyword? Because yes, yes it does. I don’t recall if it’s case sensitive, but I type it lower case. [import]uid: 12108 topic_id: 9812 reply_id: 35765[/import]
My bad although I’m blaming the lack of examples in the Programming In Lua ebook!
all the logical operators can be used in an if statement… duh, e.g. like a card game
if handScore < dealerScore or (handScore == dealerScore and handHiCard <=dealerHiCard) then
loseHand()
else
useful in games where you need to test several arbitrary conditions at once
Thanks again for your help! [import]uid: 3093 topic_id: 9812 reply_id: 35861[/import]
Isn’t it ‘&&’? Or just ‘AND’? I had this excellent website where the difference between for example Javascript and PHP and LUA was shown, but i can’t find it.
You can’t use the usual ‘&&’ in Lua. But I like ‘and’ more anyway. Who the hell came up with such ugly stuff? “&&, ||” [import]uid: 51516 topic_id: 9812 reply_id: 35873[/import]
Considering your code looks fine to me, I still don’t get what you are asking. I mean, have you actually tried to run your code and you got an error?
Who the hell came up with such ugly stuff? “&&, ||”
C used && for the boolean “and” because & is a bitwise “and”. Which is still kinda unfriendly (I’d much rather the other way around, because how often are you doing bitwise operations) but at least it makes sense. [import]uid: 12108 topic_id: 9812 reply_id: 35902[/import]
the reason for asking originally is that I couldn’t find any examples in the programming guide with an if statement
after your prompt I tried and at first I got an error due to typos and local / global variable errors but from my post above it works. Thanks [import]uid: 3093 topic_id: 9812 reply_id: 35920[/import]