A to Z Scripting: Basic maths: Difference between revisions
mNo edit summary |
mNo edit summary |
||
Line 1: | Line 1: | ||
== Basic maths symbols == | |||
You can use basic maths symbols, as well as brackets (parentheses): | You can use basic maths symbols, as well as brackets (parentheses): | ||
{| class="wikitable" | {| class="wikitable" | ||
Line 15: | Line 14: | ||
|} | |} | ||
== The = sign == | |||
An important difference is what the = sign does. In scripting, = means "set", while == means "equals". | An important difference is what the = sign does. In scripting, = means "set", while == means "equals". | ||
teleport_destination = '20 20 20'; //set teleport_destination to '20 20 20' | teleport_destination = '20 20 20'; //set teleport_destination to '20 20 20' | ||
Line 22: | Line 21: | ||
== Combining == | |||
You can freely combine script events, variables and absolute values in one line like this: | You can freely combine script events, variables and absolute values in one line like this: | ||
teleport_destination = $player1.getOrigin() + teleportation_offset + '0 0 16'; | teleport_destination = $player1.getOrigin() + teleportation_offset + '0 0 16'; | ||
Line 28: | Line 27: | ||
Strings can be cobbled together from strings, floats and vectors with the + sign. This is quite useful for sending helpful messages to the console: | Strings can be cobbled together from strings, floats and vectors with the + sign. This is quite useful for sending helpful messages to the console: | ||
sys.println(entity1 + " is at the location " + | sys.println(entity1 + " is at the location " + entity1.getOrigin()); | ||
== Increasing/decreasing == | |||
Increasing (incrementing) a variable's value by 1 would work like this: | Increasing (incrementing) a variable's value by 1 would work like this: | ||
counter = counter + 1; //set "counter" to: the current value of "counter" + 1 | counter = counter + 1; //set "counter" to: the current value of "counter" + 1 |
Revision as of 15:51, 21 December 2020
Basic maths symbols
You can use basic maths symbols, as well as brackets (parentheses):
symbol | effect | can be used with |
---|---|---|
+ | add/combine | floats, vectors, strings |
- | subtract | floats, vectors |
* | multiply | floats |
/ | divide | floats |
The = sign
An important difference is what the = sign does. In scripting, = means "set", while == means "equals".
teleport_destination = '20 20 20'; //set teleport_destination to '20 20 20' float1 = float2 + float3; //set float1 to the sum of float2 and float3 if ( float1 == float2 ) //check if float1 is equal to float2
Combining
You can freely combine script events, variables and absolute values in one line like this:
teleport_destination = $player1.getOrigin() + teleportation_offset + '0 0 16';
Strings can be cobbled together from strings, floats and vectors with the + sign. This is quite useful for sending helpful messages to the console:
sys.println(entity1 + " is at the location " + entity1.getOrigin());
Increasing/decreasing
Increasing (incrementing) a variable's value by 1 would work like this:
counter = counter + 1; //set "counter" to: the current value of "counter" + 1
An alternative method to increase a variable by 1 is:
counter++; //increase "counter" by 1 counter--; //decrease "counter" by 1
Vectors
You can add or subtract vectors from each other. Things like multiplication or finding the magnitude require script events such as DotProduct(), CrossProduct() and vecLength().
You can access individual components of a vector variable by appending _x, _y or _z to the name, i.e. teleport_destination_z. These will be floats.
More detail on vector maths and what you can do with it in A to Z Scripting: Special methods.
Next / previous article
- Next article: A to Z Scripting: Setting up the .script files
- Previous article: A to Z Scripting: More scripting basics
- Table of contents: A to Z Scripting