|
if THIS or THAT then
^Let's look at the statement above. What I'm wondering is if the condition of "THIS" is met, will it still read to check if it meets "THAT" or will it just skip over it?
I've used some languages where it will ignore anything past or if it meets the first condition, was wondering how it worked on here. I strangely can't find any documentation telling me. |
|
|
Treat it as a conditional statement if x doesn't exist but y exists then do func but if x and y don't exist end
#code "Lua ~ PHP ~ CSS ~ HTML for me at least." |
|
|
If I had to guess it would ignore the second statement. Interesting question, how would you test it? I've seen variables being assigned like
Var = NumberVar or 0 --Or something like that |
|
FabunilJoin Date: 2013-10-25 Post Count: 4325 |
It skips over it, you can also easily test this:
print(true or workspace.THIS_OBJECT_DOESNT_EXIST) > true
print(false or workspace.THIS_OBJECT_DOESNT_EXIST) > should throw an error |
|
FabunilJoin Date: 2013-10-25 Post Count: 4325 |
"I've seen variables being assigned like
Var = NumberVar or 0 --Or something like that"
Var = statement or something
is basicly a shorter version of
if statement == true then
Var = something
end
You can also do
Var = statement1 and something1 or statement3 and statement4 and something2 or something3
which is basicly the same as
if statement1 == true then
Var = something1
elseif statement2 == true and statement3 == true then
Var = something2
else
Var = something3
end
|
|
|
The "or" statement works like the word "or" but the possibility of both being true, still counts as "or" being true. Meaning:
x = 1
y = 0
if x == 1 or y == 1 then -- This statement is "true".
end
--//
x = 1
y = 1
if x == 1 or y == 1 then -- This statement is also "true".
end
--//
x = 1
y = 1
if x == 0 or y == 0 then -- This statement is "false".
end
--//
The "and" statement requires both statements to be true:
x = 1
y = 1
if x == 1 and y == 1 then -- true
end
--//
x = 1
y = 0
if x == 1 and y == 1 then -- false
end
--//
x = 0
y = 0
if x == 1 and y == 1 then -- false
--//
~MightyDantheman |
|
|
"Var = statement or something
is basicly a shorter version of
if statement == true then
Var = something
end"
Not really
Var = x.Value or y
If first value is nil then Var would be second value
#code "Lua ~ PHP ~ CSS ~ HTML for me at least." |
|
FabunilJoin Date: 2013-10-25 Post Count: 4325 |
My bad, I need some sleep |
|
|
riftgJoin Date: 2008-11-24 Post Count: 1980 |
8A6EFACA
@Fabunil
Do s have bad, HE need some sleep?
jk I don't mean it
RiftG never sleeps |
|
riftgJoin Date: 2008-11-24 Post Count: 1980 |
866BEF9C
@greedyawesomeman
jk I don't mean it
RiftG never sleeps |
|
OakBerryJoin Date: 2015-05-18 Post Count: 407 |
It could be either.
a = true
a = false
if a == true or b == true then
print("this will print because a is true")
end |
|
cgjnmJoin Date: 2011-12-22 Post Count: 2347 |
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:wait()
if player.Character is not a thing, it will go to the latter. |
|
Wizj0ckedJoin Date: 2013-09-03 Post Count: 15938 |
SEND ME A TRADE PLEASE I WILL A/C! :) I HAVE RAINBOW FEDORA, DESERT SCOUT AND OTHER ITEMS!!! SEND PLEASE!!! |
|
OakBerryJoin Date: 2015-05-18 Post Count: 407 |
oops I meant to say 'b = false' |
|