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.
Impulse List:
- Wake Up
- Triggers whenever the AI switches from inactive to active.
- New Round
- Triggers whenever a new Tower Testing round starts.
- Open: Buildings
- Triggers whenever the window of the building is being opened (ex: Open: Arcade)
- Key: 0-9
- Triggers whenever the 0-9 key is being pressed (not numpad). (ex: Key: 0)
- Key: A-Z
- Triggers whenever the A-Z key is being pressed. (ex: Key: A)
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. All conditions are of data Type:Bool.
Condition List:
- Comparison: Data Type
- Compares two Data Type values based on the selected operator. Allowed operators are "=="/"=" (Equals), "!=" (Not Equal), "&&"/"&" (Both must be true), "||"/"|" (Either has to be true). (ex: Comparison: Bool).
- Factory: Is Processing
- Returns true if the machine with ID Machine is currently processing items. (ex: Factory: Is Processing (Oven))
- Mine: Has Layers
- Returns true if the current active mining tab can generate at least 1 layer.
- Museum: Fill Inventory
- Returns the current Fill Inventory state
- String: Contains
- Returns true if the string "String" contains the string "String". (ex: "Catch" Contains "Cat")
- Tower: Is Stunned
- Returns true if the tower is stunned and false if the tower is either not stunned or does not exist.
- Town: Window Open
- Returns true if the Buildings window is active and visible on the screen. (ex: Tower Testing is open)
Action
An Action is something that the AI does when the script becomes active. The Actions are executed one by one, in order from top to bottom. Actions will continue to be executed until either the AI menu is closed, or the script terminates normally. There is currently no way to execute more than one Action at a time.
Action List (descriptions are their defaults as they are seen in-game):
- Basic: Goto
- Jumps to line 0. The first line in the script equals 1. Entering an invalid line number will result in the value being clamped between the min. and max. boundaries during execution.
- Basic: Goto-If
- Jumps to line 0 in the current script if False is True. First line equals 1.
- Basic: Click
- Performs a mouse click at following location: (X: 0, Y: 0).
- Basic: Slider
- Sets the slider position (X: 0, Y: 0) on the screen to 0.0 with 0 being the leftmost and 1 being the rightmost end.
- Basic: Scrollrect
- Scrolls within a scrollable container at (X: 0, Y: 0) to 0.0 (horizontally) and 0.0 (vertically) with 0 being the left/lower end and 1 being the right/upper end. Use a negative value to ignore an axis.
- Basic: Wait
- A simple wait function that stops the current script for a total of 0.0 seconds.
- Basic: Wait Until
- Stops the current script until False becomes True.
- Basic: Wait While
- Stops the current script as long as False is True.
- Basic: Execute
- Executes the first script in the list which is named "Empty" without requiring an impulse. Conditions of the script called still have to be fulfilled.
- Basic: Execute (Sync)
- Executes the first script in the list which is named "Empty" and waits until the execution is completed. Conditions of the script still have to be fulfilled.
- Basic: Stop
- Stops the execution of all scripts and script instances which are named "Empty".
- Global: Set (Double / Int / String)
- Creates or changes the global variable "Empty" to contain the value 0.0 / 0 / string "Empty".
- Global (Unset)
- Deletes the global variable with the name "Empty".
- Local: Set (Double / Int / String)
- Creates or changes the local variable "Empty" to contain the value 0.0 / 0 / string "Empty".
- Local: (Unset)
- Deletes the local variable with the name "Empty".
- Tower: Use (Instantly)
- Orders the Tower to use the Modules at slot 1 where slot 1 refers to the module at the very top of the skill menu. Entering an invalid slot will do nothing.
- Tower: Restart
- Restarts the current Tower Testing run. Can only be can only be executing during or at the end of a run that took equal or longer than a second.
- Town: Open Window
- Opens the Tower Testing window if True is True, otherwise it will be closed. Opening or closing windows this way does not play the transition animation!
- Mine: Dig
- Mine: New Layer
- Mine: Open Tab
- Opens the mining tab at position 1. Position 1 is the first tab (Orange) and position 12 is the last tab (Black).
- Factory: Try Craft
- Tries to craft Motor (T1) a total of 1.0 times by using only items inside the main inventory. If that is not possible then no items are being crafted. Only works if the Factory screen is visible.
- Factory: Try Produce
- Tries to put 1.0 x Ore (T1) into machine Oven. If too few items are available or the selected machine is currently busy with a different item type then nothing will happen. Ignores the tier if the selected item ID is rubber.
- Factory: Trash
- Powerplant: Sell
- Sells the Power Plant component at X: 0 and Y: 0 and automatically refunds a part of the selling price. If the selected slot is empty then nothing will happen. (0, 0) is the bottom left corner of the grid.
- Tradingpost: Refresh
- Generates a new set of offers in the Trading Post. Requires a specific upgrade for the Trading Post later in the game in order to be used!
- [spoiler] Requirements [/spoiler]
- Generates a new set of offers in the Trading Post. Requires a specific upgrade for the Trading Post later in the game in order to be used!
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.