Skip to content
MineGame159 edited this page Jan 14, 2023 · 8 revisions

Runtime errors

When a runtime error happens a StarscriptError exception is thrown.

Expressions

Every expression needs to be surrounded by {}. Expression blocks can be nested where other expressions are required.

Variables

Variables can be simply accessed by their name anywhere in an expression. They can be different every time they are used. You cannot assign new values to variables. When the script tries to access a variable that doesn't exist, it throws a StarscriptError with a descriptive message.

Values

There are 6 value types:

Null

Null represents nothing and is not used by default anywhere.

Booleans

Can only be true or false.

Numbers

In Java, Starscript numbers are defined as double. When a number with no decimal places is printed it doesn't append .0 after it, unlike in Java.

Strings

String is just a bunch of text surrounded by ' or ".

Functions

Functions can only be defined in Java and can take any number of arguments. Functions are called like this: foo(), bar(5, true).

Maps

Maps can only be defined in Java and act as a collection of other values. Values inside a map are accessed using ., for example: player.name.
When converting map to a string Starscript looks for a field named _toString and evaluates it if it is present.

Operators

There are 5 operators:

  • Addition +: Will add 2 strings or 2 numbers together.
  • Subtraction -: Will subtract 2 numbers.
  • Multiplication *: Will multiply 2 numbers.
  • Division /: Will divide 2 numbers.
  • Remainder %: Will calculate a remainder after a division of 2 numbers.
  • Exponentiation ^: Will raise the first number to the power of the second number.
  • And and: Will result in true if both values are truthy.
  • Or or: Will result in true if one of the values is truthy.

Operators follow standard precedence and can be grouped inside parentheses ().

Conditional operator

A value can be generated conditionally as <condition> ? <expression when condition is true> : <expression when condition is false>. Example: happy ? 'happy' : 'sad'.

Comparators

There are 6 operators:

  • Equals ==: Will check if two values are equal.
  • Not equals !=: Will check if two values are not equal.
  • Greater >: Will check if the first number is greater than the second.
  • Greater equal >=: Will check if the first number is greater or equal to the second.
  • Less <: Will check if the first number is less than the second.
  • Less equal <=: Will check if the first number is less or equal to the second.

Standard variables

  • PI: Variable that hold the number of PI.
  • time: Returns time in HH:mm format. (Can be changed with StandardLib.timeFormat)
  • date: Returns date in dd. MM. yyyy format. (Can be changed with StandardLib.dateFormat)
  • round(number), round(number, decimalPlaces): Rounds the number to 0 or the specified number of decimal places.
  • roundToString(number), roundToString(number, decimalPlaces): Rounds the number to 0 or the specified number of decimal places while converting the number to string and preserving decimal place zero (such as 5 is printed as 5.0)
  • floor(number): Removes decimal places from a number without rounding.
  • ceil(number): Always rounds up.
  • abs(number): Returns the absolute value of a number.
  • random(), random(min, max): Generates a random number.
  • string(value): Converts the value to string.
  • toUpper(string): Makes every character in a string uppercase.
  • toLower(string): Makes every character in a string lowercase.
  • contains(string, string): Checks if the first string contains the second one.
  • replace(string, string, string): Replaces every occurrence of the second string with third string in the first string.
  • pad(value, number): Pads the value (automatically converted to string) to the left if the number is positive or to the right if negative.

Standard variables are defined in StandardLib.