Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

Is this how you list names?

Asked by 8 years ago

I dont really list names of things but im not sure if this is the way you can do it.

if child.Name == "Brick3" or "Brick2" and "Brick4" then

2 answers

Log in to vote
1
Answered by
Unclear 1776 Moderation Voter
8 years ago

I'm guessing your question is more about how to chain conditionals.

You need to explicitly state each condition. Every or and and is a divider that splits up your conditions. Right now, your condition is

if child.Name == "Brick3" or "Brick2" and "Brick4" then

but it is interpreted as

if (child.Name == "Brick3") or ("Brick2") and ("Brick4") then

where the conditions in parenthesis are evaluated first into booleans, and then the entire statement is evaluated. In Lua, strings are always evaluated as true. This means that "Brick2" and "Brick4" will always be true, so this entire condition will always be true. That is not intended behavior, so we need to check if child.Name is equal to each of the strings instead of attempting a shorthand like this.

if child.Name == "Brick3" or child.Name == "Brick2" and child.Name == "Brick4" then

Now, your condition will never evaluate as true. A quick look will reveal that this condition is checking if child has a Name equal to two different values. This is not possible. I suggest reforming your condition so it makes more sense.

0
yona go back to lua learners stop steelin my rep QQ NotSoNorm 777 — 8y
0
XD pluginfactory 463 — 8y
0
Thank you. UltraUnitMode 419 — 8y
Ad
Log in to vote
2
Answered by
NotSoNorm 777 Moderation Voter
8 years ago

ononono you'd have to make it exact

so like this:

if child.Name == "Brick3" or child.Name == "Brick2" and child.Name ==  "Brick4" then

Answer this question