IF Functions
As you may or may not know the key to scripting lies in the ability to use IF statements. If statements can be simple or can be insanely complex, so lets first start off with a simple if statement:
IF <A>==B
In Sphere terms this means "IF A is equal to B then the IF Statement will continue.
IF <A>==B
SAY Hello World!
Now we have something we want the IF statement t to do if A equals B, the person or thing that this IF statement is entered on will say "Hello World!" Now we have an IF and a solution we must end the statement
IF <A>==B
SAY Hello World!
ENDIF
The statement has been finished, fantastic, but this statement seems a little one-sided so lets add an ELSE, and ELSE is triggered if nothing else in the statement returns true.
IF <A>==B
SAY Hello World!
ELSE
SAY Goodbye World!
ENDIF
Now we have given the IF statement another possible outcome, ELSE triggers when the IFs and ELIFs (we'll go into that later) fail to return true, so now this function will return something no matter what where as with our original it only had one chance to work, but now lets look at ELIF. ELIF is an "Else IF" statement and can also be represented with ELSEIF but you should try to keep your programs as short as possible. ELIF provides an alternative outcome similar to IF
IF <A>==B
SAY Hello World!
ELIF <A>>B
SAY Hey World!
ENDIF
This statement reads "If A is equal to B SAY Hello World. Else IF A is greater than B SAY Hey World!" now this statement has two chances of going off but just to be safe we'll add in the ELSE statement
IF <A>==B
SAY Hello World!
ELIF <A>>B
SAY Hey World!
ELSE
SAY Goodbye World!
ENDIF
Now we have a pretty nifty IF statement, this one reads "IF A is equal to B SAY Hello World, Else IF A is greater than B SAY Hey World! ELSE SAY Goodbye World!" and our statement is complete, now lets do a trigger for a container so i can show you return values.
Our container is set up properly and we have an @DCLICK trigger, that means "Double Click"
ON=@DCLICK
IF <src.str>>10
RETURN 0
ELSE
RETURN 1
ENDIF
Now this statement reads "On a double click IF the source (person who double clicked it) str is greater than 10 (11 or above) continue normally, ELSE end the function" What that means is if the container is double clicked and the person who double clicked it has more than 10 strength the hardcoded function (the chest opening and the player seeing whats inside) will continue normally else the function will cancel the hardcoded and the chest will remain closed. This can be very handy in scripts where you dont want the hardcoded (stuff that was programmed in) to trigger like a chest opening when you double click it, just remember RETURN 0 acts as if nothing happened and allows the game to continue and RETURN 1 stops it completely.
You are now well on your way in scripting arguments into your sphere scripts, best of luck.
Kassoon
Sardonika