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: ternery operators...

Previous Thread :: Next Thread 
blueymaddog is not online. blueymaddog
Joined: 23 Sep 2009
Total Posts: 5459
25 Feb 2012 11:27 PM
i think that's what they're called. it's a bit like if statements except sorta simplified to a variable. eg:

var = 5
var2 = var or 10 --makes var2 have the value of 'var' if it exists eitherwise it sets it to 10



can someone explain the logic when you use 'and' into it?
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
25 Feb 2012 11:31 PM
var2 = 10

When using it like this I think it takes the last arguement, which one be 10.

Just like saying this way

You can't do this.

script.Parent.CFrame = CFrame.new(0,0,0) or CFrame.new(0,0,1) or CFrame.new(0,0,2)

It wouldn't be random, it takes the last piece of code you said.
Report Abuse
blueymaddog is not online. blueymaddog
Joined: 23 Sep 2009
Total Posts: 5459
25 Feb 2012 11:32 PM
did u read my post?
Report Abuse
blueymaddog is not online. blueymaddog
Joined: 23 Sep 2009
Total Posts: 5459
25 Feb 2012 11:32 PM
"can someone explain the logic when you use 'and' into it?"

" when you use 'and' "
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
25 Feb 2012 11:33 PM
It's kinda like the same thing.

and takes the last piece of code too.

Though, you use it when both pieces of code are true.
Report Abuse
blueymaddog is not online. blueymaddog
Joined: 23 Sep 2009
Total Posts: 5459
26 Feb 2012 01:02 AM
oh, cool! i'll experiment around with it and see what i can find :)
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
26 Feb 2012 01:05 AM
Have fun testing things...
Report Abuse
blueymaddog is not online. blueymaddog
Joined: 23 Sep 2009
Total Posts: 5459
26 Feb 2012 01:06 AM
i will, thats how i got good at scripting... :D
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
26 Feb 2012 01:09 AM
:D

Good to know!
Report Abuse
JulienDethurens is not online. JulienDethurens
Joined: 11 Jun 2009
Total Posts: 11046
26 Feb 2012 01:09 AM
They're not called ternary operators...
Report Abuse
JulienDethurens is not online. JulienDethurens
Joined: 11 Jun 2009
Total Posts: 11046
26 Feb 2012 01:11 AM
Actually, that works only because of the way or and and work.

Suppose you have this:

a or b

If a is true, it will return a. Otherwise, it will return b, without even checking what b is.

Suppose you have this:

a and b

If a is false, it returns a. Otherwise, it will return b, without even checking what b is.
Report Abuse
blueymaddog is not online. blueymaddog
Joined: 23 Sep 2009
Total Posts: 5459
26 Feb 2012 01:16 AM
:) here's something i found out:

var = true and 10 or "trolololol"
print("var: "..tostring(var))
>var: 10

var = 10 and true or "trolololol"
print("var: "..tostring(var))
>var: true

var = false and 10 or "trolololol"
print("var: "..tostring(var))
>trolololol

var = true and (10 or "trolololol")
print("var: "..tostring(var))
>var: 10

var = true and (false or "trolololol")
print("var: "..tostring(var))
>var: trolololol

var = true or 10 and "trolololol"
print("var: "..tostring(var))
>var: true

var = false or 10 and "trolololol"
print("var: "..tostring(var))
>var: trolololol
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
26 Feb 2012 01:19 AM
@julien

Thanks for correcting me.
Report Abuse
blueymaddog is not online. blueymaddog
Joined: 23 Sep 2009
Total Posts: 5459
26 Feb 2012 01:21 AM
so would:

a or b

be the same as:

(not a) and b
Report Abuse
JulienDethurens is not online. JulienDethurens
Joined: 11 Jun 2009
Total Posts: 11046
26 Feb 2012 01:25 AM
@blueymaddog

If you look at the operator precedence in Lua, you see that and is evaluated before or.

Therefore, in 'a or b and c', 'b and c' is evaluated first.

Remembering that and using the rules I posted above, I mentally validated each of your statements. And, in each case, I got the same answer as you. :)

Ah, the power of brain!
Report Abuse
blueymaddog is not online. blueymaddog
Joined: 23 Sep 2009
Total Posts: 5459
26 Feb 2012 01:27 AM
print(blueymaddog.BrainPower)

>0
Report Abuse
blueymaddog is not online. blueymaddog
Joined: 23 Sep 2009
Total Posts: 5459
26 Feb 2012 01:28 AM
:o
Report Abuse
JulienDethurens is not online. JulienDethurens
Joined: 11 Jun 2009
Total Posts: 11046
26 Feb 2012 01:28 AM
a or b: if a then return a else return b end

a and b: if a then return b else return a end
Report Abuse
JulienDethurens is not online. JulienDethurens
Joined: 11 Jun 2009
Total Posts: 11046
26 Feb 2012 01:31 AM
"so would:

a or b

be the same as:

(not a) and b"

Took me almost a minute to approach that question with the correct angle, really.

true or true evaluates to true.

(not true) and true evaluates to false.

Therefore, no.
Report Abuse
blueymaddog is not online. blueymaddog
Joined: 23 Sep 2009
Total Posts: 5459
26 Feb 2012 01:34 AM
i just realised that 'a or b' would be the same as 'not ((not a) and b)'

LOL!
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