hello i need i want to do something like this
if AAAAAAAA and AAAAAAAB then
love.graphics.print("blahblah")
end
2 if statements
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 12
- Joined: Mon Sep 14, 2020 8:36 am
Re: 2 if statements
Sorry am a noob but I do it like this
don't know if its the right way but it works
if AAAAAAAA then
if AAAAAAAB then
love.graphics.print("bladi bladi")
end
end
Hope it helps
don't know if its the right way but it works
if AAAAAAAA then
if AAAAAAAB then
love.graphics.print("bladi bladi")
end
end
Hope it helps
Re: 2 if statements
I think you asked the same question on the Love2d subreddit, but just in case I will answer it here as well.
While you could nest "if"-statements like "RockEt__2580__" suggested I would recommend using "and". It's a cleaner solution and it's meant for exactly this situation.
This will trigger if a is 10 and b is 20. It will NOT trigger if only a is 10 or if only b is 20. If you want it to tigger when either of them is true, then you need to use "or".
While you could nest "if"-statements like "RockEt__2580__" suggested I would recommend using "and". It's a cleaner solution and it's meant for exactly this situation.
Code: Select all
if a == 10 and b == 20 then
print("hello world")
end
- zorg
- Party member
- Posts: 3465
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: 2 if statements
One more thing i can think of about how one could logic out stuff wrong:
These will work too, but not how and why you might think.
"10 and 20" and "10 or 20" might be logical in english when you combine it with the question "is the variable a equal to...", but lua code doesn't work that way. you need to duplicate the variable and the check for all logical clauses. in my example, 20 will always evaluate to true, since it's truthy, just like anything else that's not false or nil.
Code: Select all
if a == 10 and 20 then
-- blah
end
if a == 10 or 20 then
-- blah
end
"10 and 20" and "10 or 20" might be logical in english when you combine it with the question "is the variable a equal to...", but lua code doesn't work that way. you need to duplicate the variable and the check for all logical clauses. in my example, 20 will always evaluate to true, since it's truthy, just like anything else that's not false or nil.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Who is online
Users browsing this forum: No registered users and 5 guests