Jump to content




Conditional operator in lua


  • You cannot reply to this topic
5 replies to this topic

#1 ETHANATOR360

  • Members
  • 423 posts
  • Locationyour hardrive

Posted 22 November 2012 - 09:41 AM

is their a conditional operator in lua just like java?

#2 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 22 November 2012 - 09:44 AM

If you mean comparisons in ifs:
== | is equal to
> | is greater than
< | is less than
>= | is greater than or equal to
<= | is less than or equal to
~= | is not equal to

However if you mean something like
var = (condition) ? onTrue : onFalse;
then in lua, it's
var = condition and onTrue or onFalse


#3 Tiin57

    Java Lunatic

  • Members
  • 1,412 posts
  • LocationIndiana, United States

Posted 22 November 2012 - 09:46 AM

Just to add; I don't believe there is:
x++
x+=y
x--
x-=y


#4 ETHANATOR360

  • Members
  • 423 posts
  • Locationyour hardrive

Posted 22 November 2012 - 12:17 PM

i mean like x = y ? 1 : 0

#5 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 22 November 2012 - 12:32 PM

View PostKingdaro, on 22 November 2012 - 09:44 AM, said:

then in lua, it's
var = condition and onTrue or onFalse


#6 Watcher7

  • Members
  • 25 posts
  • LocationEquestria, TX

Posted 22 November 2012 - 12:41 PM

View PostETHANATOR360, on 22 November 2012 - 12:17 PM, said:

i mean like x = y ? 1 : 0

That's called the ternary operator.
http://codepad.org/CEtRWl6l

Kingdaro also showed you this.

EDIT: Isn't this shit supposed to alert me when someone posts something new? First the staff and recent thread frames are broken, now this.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users