Is there a built-in "AND" function/operator?

psymann
01 Apr 2013, 23:34
Hello, sorry for yet another question :oops:

What I want to code now is:


IF ( Something = True AND Somethingelse = TRUE ) {
dosomething
}

Is there an "AND" operator I can use for this? I've mostly been using the code interface rather than the raw code screen, and can't see a way of adding an AND.

Or do I need to use nested IFs?

IF ( Something = True) {
IF ( Somethingelse = True) {
do something
}
}

psymann

jaynabonne
01 Apr 2013, 23:36
Yes, it's called "and" :)

What you typed should probably work. It's not in the interface since basically it's part of an expression.

IF ( Something and Somethingelse) {
dosomething
}

psymann
01 Apr 2013, 23:38
hee hee, ok, that was an easy one ;-)

so as long as I ditch the friendly interface and go hardcore with the code screen (or pick "expression" from the friendly interface to type code into) I'm ok :)

thanks!
psy

jaynabonne
01 Apr 2013, 23:42
To be honest, you *can* do it with nested if's if you want... it's up to you. :)

There's also "or" and "not".

if ((a or b) and not c) {
...
}


It's the same if you wanted to check "x > 1" or "x + y <> z". You'd have to type it in. So, yes... expressions. :)

HegemonKhan
02 Apr 2013, 02:17
I'm a bit confused about the differences (in how to properly use the "and" vs "or"), so let me take a stab at it, and then you can tell me if I got it right or not.

--------

AND:

"and" means that both sides of it are used in the requirement of the script line:

if ("ball" is "color:red" and "shape:round"), then "bob takes the ball":

if the ball is color:red but shape:square, then bob does not take the ball, correct?

so, "and" is kinda like multiple nested IF scripts, in a way (or a very slight way lol), correct?

--------

OR:

"or" means that both sides are independent from each other, if the left side doesn't pass the test, then the right side is tested if it passes the test or not (or vice-versa):

if ("ball" is "color:red" or "shape:round"), then "bob takes the ball":

if the ball is color:red (and regardless of its shape), then bob takes the ball, correct?

if the ball is shape:round (and regardless of its color), then bob takes the ball, correct?

so, "or" is kinda like an ELSE script, in some way (or in a very slight way lol), correct?

--------

NOT:

and of course, if these are correct about "and" and "or", then the same applies with the usage of "not" with them, in the new context of "not" being used, as I don't think I need to ask about this, with using "not", as I presume "not" is logical in context with the usage of "and" vs "or", correct?)

HegemonKhan
02 Apr 2013, 02:40
for psymann:

the msg script, is like the bridge between the GUI-Editor mode and the Code View (or just the code) mode.

when you do:

Add a new script -> Output -> Print a mesage -> [EXPRESSION] -> (whatever)

you can do anything, it is like a code command promptor for the GUI-Editor mode.

for example:

Add a new script -> Output -> Print a mesage -> [EXPRESSION] ->

Print [EXPRESSION] player.strength = 0

is the exact same thing as:

Add a new script -> Variables -> Set a variable or attribute ->

Set variable _____ = [EXPRESSION] ______

Set variable player.strength = [EXPRESSION] 0

-----------

so, basically, "Add a new script -> Output -> Print a mesage -> [EXPRESSION] ->" let's you type in code into the GUI-Editor mode

or, to put it another way:

ALL CODE is recognized from this code line:

msg (______) <-> this is what it looks like in code (or in code view mode)

you can put ANY code into "msg (______)" and it will work

or when in the GUI-Editor mode:

you can put ANY code into "Add a new script -> Output -> Print a mesage -> [EXPRESSION] ->" and it will work (save it and then re-look at it, notice how it changes from "Print a mesage -> [EXPRESSION] ->" to its proper GUI-Editor form of what you typed in? hehe)