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

I do not understand the 'And' function, please explain with an example ?

Asked by 7 years ago

So like the title says, I've been trying to understand how to use the 'and' function in scripting, but I just don't know how should I use it properly...

Example of how I understand how to use it:

1if A and B == true then
2some stuff
3end

That's how I understand how to use it, but it's incorrect...

4 answers

Log in to vote
0
Answered by
arshad145 392 Moderation Voter
7 years ago

Hello,

1local A,B = 0,1 -- A is 0 but B is 1
2 
3if A == 1 and B == 1 then -- if A AND B are both 1.
4    print("true AND "..A,B)
5else
6    print("FAIL AND "..A,B)
7end

OUTPUT : FAIL AND 0 1

1local A,B = 0,1 -- A is 0 but B is 1
2 
3if A == 1 or B == 1 then -- if A is 1 OR B is 1.
4    print("true OR "..A,B)
5else
6    print("FAIL OR "..A,B)
7end

OUTPUT : true OR 0 1

The and operator will check if both statements are matching the desired value. In this case if A == 1 and B == 1 then , but A is 0 and B is 1 . So, the statement results in a false and prints the above.

The or operator will check if atleast one statement is matching the desired value. In this case if A == 1 or B == 1 then , A is 0 so the first statement is false, but B is 1. So, it is indeed a true statement as atleast one statement is true. Therefore , it will give the above output.

Thank you for reading.

Feel free to ask any questions.

Ad
Log in to vote
0
Answered by
Meqolo 78
7 years ago
1if A == true and B == true then
2--code
3end
Log in to vote
0
Answered by 7 years ago

You need a variable or something to define 'A' and 'B' and those two values, the 'if' loop only will activate ONCE so use a 'loop', functions or something for the loop to activate properlly.

0
Thanks, but I knew about the rest, I only needed help with the understandment of 'And' LordTechet 53 — 7y
Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

The "and" function is seeing if there are two things being used. The example you wanted,

1if == true
2and
3B == true
4then
5game.lighting.fogcolor = ('Pink')
6end

If this helped, please accept!

Answer this question