|
| 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
|
  |
| 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 |
|
|
| |
|
|
| 25 Feb 2012 11:32 PM |
"can someone explain the logic when you use 'and' into it?"
" when you use 'and' " |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 26 Feb 2012 01:02 AM |
| oh, cool! i'll experiment around with it and see what i can find :) |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 26 Feb 2012 01:05 AM |
| Have fun testing things... |
|
|
| Report Abuse |
|
|
|
| 26 Feb 2012 01:06 AM |
| i will, thats how i got good at scripting... :D |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
| |
|
|
| 26 Feb 2012 01:09 AM |
| They're not called ternary operators... |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 26 Feb 2012 01:19 AM |
@julien
Thanks for correcting me. |
|
|
| Report Abuse |
|
|
|
| 26 Feb 2012 01:21 AM |
so would:
a or b
be the same as:
(not a) and b |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 26 Feb 2012 01:27 AM |
print(blueymaddog.BrainPower)
>0 |
|
|
| Report Abuse |
|
|
| |
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|