Stranded


Scripting - IV. Conditions
By the usage of conditions, you can let certain circumstances in the game (which can be checked per commands or read out of variables) influence scripts (and consequently, what happens afterwards).
The essential command behind it is "if".

• The command "if" in the command reference

It serves to formulate a condition that is to be attached within the round brackets that follow. If it is fulfilled, the script that is in the subsequent curly brackets will be executed. Otherwise, it will not.
Hereafter, the examplary conditions are all constructed with numbers; but logically, those could as well be replaced by variables or return-commands! A simple example:
on:start {
	if (5==5){
		msg "5 equals 5!";
	}
}

The msg-command is executed, because 5 undoubtably equals 5. You must keep in mind that for comparisons, you have to use a double equal sign instead of just one. Apart from "equals", you can also use "equals not", "greater than", "smaller than" etc. Detailed information about the way that is done can be found in the command reference, under the keyword "if".
If you now change one of the number, so that the "equation" becomes unequal, the command in the curly brackets will not get ran anymore.
But there is also a way to let the game run alternative script commands, if the condition is not met. Herefore, you can use "else" to extend the condition. It is simply added behind the curly brackets of the if-command and anon brings about its own curly brackets, which the alternative commands can be written into:
on:start {
	if (3==5){
		msg "3 equals 5!";
	}else{
		msg "3 doesn't equal 5!";
	}
}

This will produce the output "3 doesn't equal 5!". If everything is alright with the universe, the condition is not met.
But this is not all yet. The whole if-contraption can be further pimped with the elesif-command. Elseif is about like an else, but brings along its own new condition. In practise, this is what it looks like:
on:start {
	if (3==5){
		msg "3 equals 5!";
	}elseif (2==2){
		msg "3 doesn't equal 5 and 2 equals 2";
	}else{
		msg "3 doesn't equal 5 and 2 doesn't equal 2";
	}
}

Instead of else, one could just as well have used another "elseif". This chain of conditions can be infinitely extended.
There is, however, another way to express complex conditions: Linking them with "and", "or" etc. within the condition brackets itself:
on:start {
	if ((3==5)&&(2==2)){
		msg "3 equals 5 and 2 doesn't equal 2";
	}else{
		msg "No way! Either, 3 doesn't equal 5, or 2 doesn't equal 2!";
	}
}

"&&" stands for "and" - which you can also look up in the command reference under "if". Only if 3 equals 5 AND 2 equals 2, the condition is met. The whole procedure can be extended with many further kinds of links.
It is important to always write these components into round brackets.

Summary

The structure of conditions always looks as it follows: "If (condition){commands}". Via "else", "elseif" and links within the conditions (such as for instance "and" or "or"), they are expandable.

• V. Scripts & Infos
Stranded I, Stranded II & Stranded III are games by Unreal Software 2003-2023 | Contact | Disclaimer