Skip to content

Scripting Language Reference

Igor Budzhak edited this page May 7, 2023 · 7 revisions

Introduction

Scripting language was designed to be Java-like but more noob-friendly. API methods are also designed to be noob-proof. It should be hard to crash the game if you write stupid script.

You can see language grammar file here: https://github.com/Zergatul/cheatutils/blob/master/src/main/java/com/zergatul/cheatutils/ScriptingLanguage.jj

Lexical analysis

Operators

The following tokens are operators:

+       -       *       /       %       !/      !%
~       !       &&      ||
<       >       <=      >=      ==      !=

Data model

Types

boolean

Boolean value, same as in Java. Default value false.

int

32-bit signed integer value, same as in Java. Default value 0.

float

64-bit floating point value, same as double in Java. Default value 0.0.

string

Immutable string, like in Java. As opposed to Java cannot be null, can be compared with == or != operators.

Expressions

Conversions

If left or right operand is int and other is float, int is cast to float. Examples:

float x = 2.1;
if (2.1 > 2) { // int literal is converted to 2.0 float
    module.doSomething();
}

Same happens when you declare variable.

When you specify arguments for method call, arguments can be implicitly converted: int -> float, int -> string. Compiler finds acceptable method overload which requires minimum type conversions.

Conditional expression

Example:

int x = module.isEnabled() ? 123 : 456;

Comparisons

Examples:

b = x > y; // greater than
b = x < y; // less than
b = x >= y; // greater than or equals
b = x <= y; // less than or equals

Boolean operations

Examples:

boolean b1 = x && y; // and
boolean b2 = x || y; // or
boolean b3 = !b2; // not

Unary arithmetic and bitwise operations

Examples:

x = -y;
x = +y;
x = ~y; // binary inversion

Binary arithmetic operations

Examples:

x = a + b;
x = a - b;
x = a * b;
x = a / b;
x = a % b; // remainder
x = a !/ b; // floor div, example -5 !/ 16 = -1
x = a !% b; // floor mod, example -5 !% 16 = 11

Simple statements

Variable declaration statement

Examples:

boolean b; // declaration with no initial value
int x = y + 10; // declaration with initial value

When you declare variable with no initial value it implicitly receives default initial value for its type. Variable can be accessed only within block it was declared.

Assign statement

Example:

x = x + y + module.getSomething();

Method call statement

Example:

module.setSomething(123);

Compound statements

if statement

The if statement is used for conditional execution. May contain optional else block. Examples:

if (x == y) {
    module.doSomething();
}

if (a > b) {
    module.doX();
} else {
    module.doY();
}