Constants in AngelScript

Constants are values that cannot be changed once declared. They can be of various data types including character, string, boolean, and numeric values.

const string s = "constant";

void main() {
    print(s + "\n");

    const int n = 500000000;
    const double d = 3e20 / n;
    print(d + "\n");

    print(int64(d) + "\n");
    print(sin(n) + "\n");
}

void print(const string &in text) {
    print(text);
}

double sin(double n) {
    return Math.sin(n);
}

Explanation

In the script above, we declare a constant s with a string value "constant". Then we define the main function where we:

  1. Print the constant string s.
  2. Declare an integer constant n with a value of 500000000.
  3. Declare a double constant d which performs an arithmetic operation 3e20 / n demonstrating arbitrary precision arithmetic.
  4. Print the value of d in its double form.
  5. Print the value of d after converting it to int64.
  6. Print the result of a sine operation on n.

To execute this script, ensure your environment supports AngelScript, and use the relevant commands or configurations to run the script.

Now that we’ve seen how to use constants in AngelScript, let’s explore more features of the language.