generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Just some clarification on using or to assign a variable

Previous Thread :: Next Thread 
Amalgam is not online. Amalgam
Joined: 08 Oct 2012
Total Posts: 54
21 Oct 2012 06:51 PM
'or' assigns the first non-nil value right?

like:

a = 29
b = nil
c = 35

d = a or b or c


d would equal 29 right?
then:

d = b or c or a

d would then equal 35?


I just want to know if this is really what it's doing.
Report Abuse
Woodstauk4 is not online. Woodstauk4
Joined: 27 Dec 2010
Total Posts: 3061
21 Oct 2012 06:55 PM
You mean ternary operators?

This is how they work:

variable = (condition) and (if condition is true, variable equals this) or (if condition is not true, variable is this)


local stuff = 1+2==3 and "That\s true!" or "That\s false!"

print(stuff)

> That's true!


local stuff = 1+2==4 and "That\s true!" or "That\s false!"

print(stuff)

> That's false!
Report Abuse
Amalgam is not online. Amalgam
Joined: 08 Oct 2012
Total Posts: 54
21 Oct 2012 06:58 PM
>>woodstauk4

Thanks. I was assignment with 'or' once in a code I found and wasn't sure how it worked.
Report Abuse
Amalgam is not online. Amalgam
Joined: 08 Oct 2012
Total Posts: 54
21 Oct 2012 07:04 PM
Okay so if my code is:

myValue = false
toggle=function(v) v = v and false or true return v end
print(myValue)
toggle(myValue)
print(myValue)
toggle(myValue)
print(myValue)

then the output would be:
false
true
false


Is that right?
Report Abuse
Woodstauk4 is not online. Woodstauk4
Joined: 27 Dec 2010
Total Posts: 3061
21 Oct 2012 07:06 PM
Yes.
Report Abuse
Amalgam is not online. Amalgam
Joined: 08 Oct 2012
Total Posts: 54
21 Oct 2012 07:11 PM
Thanks for teaching me this. Very helpful
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image