AI
The AI (short for "Artificial Intelligence") is a feature of the Headquarters that unlocks upon reaching Military Tier 4. It is an extremely versatile tool that allows the user to automate almost any task in the game. As of "v0.8.5 B1 - Workers!" (see Version history), Workers were added to the game as a "pre-AI automation system". According to the developers, Workers "can do exactly one specific task of your choice at a selected speed" so they aren't meant to take place of AI in any way, as AI is still more powerful in its capabilities.
To use the AI you have to create AI scripts in the headquarters, or obtain import codes for scripts that other players have written. For more information on learning how to create scripts, see Using the AI. For a list of recommended scripts, see AI Scripts Guide.
AI Scripts
An AI script contains three sections that control its behavior:
- Impulses
- Conditions
- Actions
Impulse
An Impulse can refer to any button press or event that directly activates an AI script. It is not to be confused with the Basic:Execute command which is not considered an impulse, as it is not a way for a player to directly trigger an AI script, but rather a way of calling the script inside of another AI script much like helper methods in high level programming languages. An AI script can contain 0 - 3 impulses, each of which can trigger the AI script, regardless if it has already been triggered. It is possible that a script can trigger multiple times before it has finished execution. In this case multiple instances of this script can run in parallel.
Condition
A condition is a requirement that has to be fulfilled in order for the script to start executing. If any of the specified conditions is not met then the whole script will not be executed once it is triggered by an impulse. During the execution the specified conditions have no effect.
Action
An action is something that the AI does when the script becomes active. The order of all actions is important where the action at the top is executed first and then all following actions are executed one by one. There is no way to execute multiple actions at the same time inside a single active script.
There is a maximum limit of actions per script, also often called "maximum lines." This is determined by the total amount of RAM installed in all servers. The RAM requirement is 7.98actions-7
bytes, rounded up.
RAM (bytes) | Actions | Conditions | Impulses |
---|---|---|---|
1 | 7 | 1 | 1 |
8 | 8 | 1 | 1 |
64 | 9 | 1 | 1 |
509 | 10 | 1 | 1 |
4056 | 11 | 2 | 1 |
32361 | 12 | 2 | 1 |
2.5823e5 | 13 | 2 | 1 |
2.0607e6 | 14 | 2 | 2 |
1.6445e7 | 15 | 2 | 2 |
1.3123e8 | 16 | 2 | 2 |
1.0472e9 | 17 | 2 | 2 |
8.3566e9 | 18 | 2 | 2 |
6.6686e10 | 19 | 3 | 2 |
5.3215e11 | 20 | 3 | 2 |
4.2466e12 | 21 | 3 | 2 |
3.3888e13 | 22 | 3 | 2 |
2.7042e14 | 23 | 3 | 2 |
2.1580e15 | 24 | 3 | 2 |
1.7221e16 | 25 | 3 | 2 |
To get all 25 actions requires fully upgrading the RAM of all 16 servers.
Data Types
There are various data types that are usable within AI scripts, all of which are incredibly versatile and useful in creating a script as complex or simple as one desires.
Type | Description | Example Values | Default Value | Notes |
---|---|---|---|---|
double | A integer that allows decimal precision. Can be positive or negative. | 3.2, 0.29, -10.2, 7.9999993 | 0.0 | Doubles have a max value of approximately 1.8 × 10308. |
int | A number that does not allow decimal precision. Can be positive or negative. | 20, 69, 420, -1029, 0 | 0 | |
string | An array of characters. Basically a way to format and use text. | "meow", "hello", " ", "I am a text" | "" | The quotes in the examples are not included in the actual string value. |
bool | A binary value that can either be true or false. | true, false | false | |
Vector2 | A container type that contains two double values called x and y. | (-30.0, 0.0), (28.38, 13) | (0.0, 0.0) |
Some datetypes can be converted to others by using a function. Check the table below to see which datatypes are currently interchangeable.
Source / Target | double | int | string | bool | Vector2 |
---|---|---|---|---|---|
double | - | Yes | Yes | No | Partially |
int | Yes | - | Yes | No | No |
string | No | No | - | No | No |
bool | No | No | No | - | No |
Vector2 | Partially | No | No | No | - |
(The table will be updated as soon as more AI features are available.)
Functions
Any line in an AI script (apart from impulses) represents a function.
There are two major types of functions:
- Without a return value (= Actions)
- With a return value
Functions without a return value appear as actions in the sidebar of the AI-script editor. In general these functions do something specific but require some sort of input.
The various inputs to a function are called arguments. Each argument of a function has a specific datatype and accepts either a constant value or a function with a return value of the same type.