Difference between revisions of "AI"

From The Perfect Tower II
Jump to navigation Jump to search
(Change link to maintained script compendium)
(34 intermediate revisions by 9 users not shown)
Line 1: Line 1:
The AI is a very powerful tool that can be used to automate nearly anything. To use the AI you have to create AI-scripts in the headquarters.
+
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.  
  
==AI-Scripts==
+
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 available scripts, see the [https://github.com/cl1694/AI-Script-Compendium AI Script Compendium].
An AI script contains three sections that control its behaviour:
+
 
 +
==AI Scripts==
 +
An AI script contains three sections that control its behavior:
  
 
*Impulses
 
*Impulses
Line 9: Line 11:
  
 
===Impulse===
 
===Impulse===
An impulse or trigger is a certain event that activates an AI script. A script can contain zero, one or more impulses and will react to all of them equally. 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.
+
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 (<code>impulse wakeup()</code>)
 +
**Triggers whenever the AI switches from inactive to active.
 +
*New Round (<code>impulse game.newround()</code>)
 +
**Triggers whenever a new [[Tower Testing]] round starts.
 +
*Open: [[Buildings]] (<code>impulse open.&lt;building&gt;()</code>)
 +
**Triggers whenever the window of the building is being opened (ex: Open: Arcade)
 +
*Key: 0-9, A-Z (<code>impulse key.#()</code>)
 +
**Triggers whenever the 0-9 or A-Z key is being pressed (not numpad). (ex: Key: 0)
  
 
===Condition===
 
===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.
+
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, and any expression that returns a bool can be used as a condition.
 +
 
 +
'''Condition List:'''
 +
 
 +
*Comparison: Bool (<code>bool comparison.bool(bool: lhs, string: op_comp, bool: rhs</code>)
 +
**Compares two boolean values based on the selected operator. Allowed operators are "=="/"=" (Equals), "!=" (Not Equal), "&&"/"&" (Both must be true), "||"/"|" (Either has to be true).
 +
*Comparison: Int/Double (<code>bool comparison.&lt;type&gt;(type: lhs, string: op_comp, type: rhs</code>)
 +
**Compares two &lt;type&gt; values based on the selected operator. Allowed operators are "=="/"=" (Equals), "!=" (Not Equal), ">", ">=", "<", "<=".
 +
*Comparison: String (<code>bool comparison.string(string: lhs, string: op_comp, string: rhs</code>)
 +
**Compares two string values based on the selected operator. Allowed operators are "=="/"=" (Equals), "!=" (Not Equal).
 +
*Factory: Is Processing (<code>bool active(string: machine)</code>)
 +
**Returns true if the machine with ID [[Machine]] is currently processing items. (ex: Factory: Is Processing (Oven)). Always returns false outside the factory.
 +
*Mine: Has Layers (<code>bool hasLayers()</code>)
 +
**Returns true if the current active mining tab can generate at least 1 layer. Always returns false outside the mine.
 +
*Museum: Fill Inventory (<code>bool isfill()</code>)
 +
**Returns the current Fill Inventory state. Always returns false outside the museum.
 +
*String: Contains (<code>bool contains(string: str, string: substr)</code>)
 +
**Returns true if the string <code>str</code> contains the string <code>substr</code>. (ex: "Catch" Contains "Cat")
 +
*Tower: Is Stunned (<code>bool stunned()</code>)
 +
**Returns true if the tower is stunned and false if the tower is either not stunned or does not exist.
 +
*Town: Window Open (<code>bool isopen(string: window)</code>)
 +
**Returns true if the [[Buildings]] window is active and visible on the screen. (ex: [[Tower Testing]] is open)
  
 
===Action===
 
===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 simply executed one by one. There is no way to execute multiple actions at the same time inside a single active script.
+
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. Within one instance of a script, there is no way to execute more than one Action at a time (but by launching multiple copies of a script, this can be achieved).
 +
 
 +
'''Action List:'''
 +
 
 +
*Basic: Goto (<code>goto(int: line)</code>)
 +
**Jumps to line <code>line</code>. 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 (<code>goto(int: line, bool: condition)</code>)
 +
**Jumps to line <code>line</code> in the current script if <code>condition</code> is True. First line equals 1.
 +
*Basic: Click (<code>click(vector: pos)</code>)
 +
**Performs a mouse click at following location: <code>pos</code>.
 +
*Basic: Slider (<code>slider(vector: where, double: value)</code>)
 +
**Sets the slider position <code>where</code> on the screen to <code>value</code> with 0 being the leftmost and 1 being the rightmost end.
 +
*Basic: Scrollrect (<code>scrollbar(vector: where, double: horizontal, double: vertical)</code>)
 +
**Scrolls within a scrollable container at <code>where</code> to <code>horizontal</code> (horizontally) and <code>vertical</code> (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 (<code>wait(double: value)</code>)
 +
**A simple wait function that stops the current script for a total of <code>value</code> seconds.
 +
*Basic: Wait Until (<code>waituntil(bool: condition)</code>)
 +
**Stops the current script until <code>condition</code> becomes True.
 +
*Basic: Wait While (<code>waitwhile(bool: condition)</code>)
 +
**Stops the current script as long as <code>condition</code> is True.
 +
*Basic: Execute (<code>execute(string: script)</code>)
 +
**Executes the first script in the list which is named <code>script</code> without requiring an impulse. Conditions of the script called still have to be fulfilled. Executed scripts are put at the end of the script list, and because of this they (usually) will run their first action in the same frame, since the script list pointer is still on the calling script, earlier in the script list.
 +
*Basic: Execute (Sync) (<code>executesync(string: script)</code>)
 +
**Executes the first script in the list which is named <code>script</code> and waits until the execution is completed. Conditions of the script still have to be fulfilled. '''As of 0.9.2, this has some bugs:''' If the conditions of the script are ''not'' fulfilled, <code>executesync</code> will wait forever without running anything. Also, if the executed script is killed with <code>stop</code>, execution will not continue.
 +
*Basic: Stop (<code>stop(string: script)</code>)
 +
**Stops the execution of all scripts and script instances which are named <code>script</code>. '''Important bug/feature:''' If a script stops ''itself'', the script list pointer is reset to the beginning, effectively giving everything before this script an "extra" cycle. Because scripts that have reached the end aren't cleaned up until the end-of-frame processing, this means that scripts on their last line (or that have jumped to 99) will re-execute their last line, which can cause bugs. This behavior is known as "Turbo Exec," since it can be used to build programs that execute much faster than the typical one-action-per-frame.
 +
*Global: Set (Double / Int / String)
 +
**Creates or changes the global variable "[EmptyX]" to contain the value [x.0 or if x has a decimal uses that instead] / [x] / string "[EmptyY]".
 +
*Global (Unset)
 +
**Deletes the global variable with the name "Empty".
 +
*Local: Set (Double / Int / String)
 +
**Creates or changes the local variable "[EmptyX]" to contain the value [x.0 or if x has a decimal uses that instead] / [x] / string "[EmptyY]".
 +
*Local: (Unset)
 +
**Deletes the local variable with the name "[Empty]".
 +
*Tower: Use (Instantly)
 +
**Orders the Tower to use the [[Modules]] at slot [x] where slot 1 refers to the module at the very top of the skill menu. Entering an invalid slot will do nothing.
 +
*Tower: Use (Position)
 +
**Orders the tower to use the module at slot [x] where slot 1 refers to the module at the very top of the skill menu at an offset of (X:[x], Y:[y])
 +
*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
 +
**Digs up the tile at X: [x] and Y: [y] of the currently selected resource in the [[Mine]] with (0, 0) being the top left corner. Only works if the [[Mine]] window is active!
 +
*Mine: New Layer
 +
**Generates a new layer of the currently selected resource in the [[Mine]]. Only works if the [[Mine]] window is active!
 +
*Mine: Open Tab
 +
**Opens the mining tab at position [x]. Position 1 is the first tab (Orange) and position 12 is the last tab (Black).
 +
*Mine: Delete Cluster
 +
**Removes the asteroid cluster at list position [x] where 1 represents the first cluster in the list.
 +
*Factory: Try Craft
 +
**Tries to craft "[Item]" (T[X]) a total of [y.0 or if y has a decimal uses that instead] 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 [x.0 or if x has a decimal uses that instead] x [Item] (T[y]) 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
 +
**Tries to put [x.0 or if x has a decimal uses that instead] x [Item] (T[y]) into the trash can of the [[Factory]]. If too few items are present in the inventory and the crafting grid of the [[Factory]] then it will still try to remove as many as possible. Ignores the tier for items that don't have a tier.
 +
*Powerplant: Sell
 +
**Sells the [[Power Plant]] component at X: [x] and Y: [y] 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!'''
 +
 
 +
*Tradingpost: Trade
 +
**Trades the offer at position [x] in the list of offers (first offer is at position 0) using [y.0 or if y has a decimal uses that instead] (0.15 = 15%) of the available input resources.
 +
*Museum: Fill Inventory
 +
**Sets the Fill Inventory button to the [T/F] state.
 +
*Museum: Combine
 +
**Combine [[Power Stones]] with the usual combine rules up to Tier [x] (<1 means no limit).
 +
*Museum: Transmute
 +
**Transmute [[Power Stones]]
 +
*Museum: Buy
 +
**Buy [[Power Stones|Power Stone(s)]] with element "[Element]"
 +
*Museum: Buy Market
 +
**Buy [[Power Stones|Power Stone(s)]] with element "[Element]" up to Tier 1.
 +
*Museum: Move
 +
**Move a [[Power Stones|Power Stone]] from [place] in slot [x] to [place]
 +
*Museum: Delete
 +
**Delete [[Power Stones|Power Stone]] from Inventory in Slot [x].
 +
*Museum: Delete All
 +
**Delete all [[Power Stones]] from Inventory.
 +
*
 +
*
 +
*
 +
 
 +
[[File:AI-Script-Editor.png|alt=AI-Script-Editor (Ingame)|none|thumb|362x362px|AI-Script-Editor (In game)]]
 +
 
 +
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 requirements are <code>7.98<sup>actions-7</sup></code>, <code>7.98<sup>8*conditions-12</sup></code> and <code>7.98<sup>11*impulses-15</sup></code> bytes, rounded up. The largest requirement takes effect - they're not added together.
  
==Datatypes==
 
There are various types for data objects, placeholders or function arguments with each representing a different format of information.
 
 
{| class="wikitable"
 
{| class="wikitable"
|+
+
!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||3
 +
|}
 +
 
 +
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.
 +
{| class="wikitable"
 
!Type
 
!Type
!Human readable description
+
!Description
 
!Example Values
 
!Example Values
 
!Default Value
 
!Default Value
Line 28: Line 190:
 
|-
 
|-
 
|double
 
|double
|A number with decimal places. Can be positive or negative
+
|A integer that allows decimal precision. Can be positive or negative.
 
|3.2, 0.29, -10.2, 7.9999993
 
|3.2, 0.29, -10.2, 7.9999993
 
|0.0
 
|0.0
|
+
|Doubles have a max value of approximately 1.797 × 10<sup>308</sup>.
 
|-
 
|-
 
|int
 
|int
|A number without decimal places. Can be positive or negative.
+
|A number that does not allow decimal precision. Can be positive or negative.
 
|20, 69, 420, -1029, 0
 
|20, 69, 420, -1029, 0
 
|0
 
|0
|
+
|Ints range from -2147483648 to 2147483647
 
|-
 
|-
 
|string
 
|string
|A chain of characters, basically any form of text.
+
|An array of characters. Basically a way to format and use text.
|"meow", "hello", " ", "I am a text"
+
|"meow", "hello", " ", "I am a text", "!BanBudE"
 
|""
 
|""
 
|The quotes in the examples are not included in the actual string value.
 
|The quotes in the examples are not included in the actual string value.
Line 57: Line 219:
 
|
 
|
 
|}
 
|}
 +
Some datatypes can be converted to others by using a function. Check the table below to see which datatypes are currently interchangeable.
 +
{| class="wikitable"
 +
!Source / Target
 +
!double
 +
!int
 +
!string
 +
!bool
 +
!Vector2
 +
|-
 +
!double
 +
|<nowiki>-</nowiki>
 +
|Yes
 +
|Yes
 +
|No
 +
|Partially
 +
|-
 +
!int
 +
|Yes
 +
| -
 +
|Yes
 +
|No
 +
|No
 +
|-
 +
!string
 +
|Yes
 +
|Yes
 +
| -
 +
|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.
 +
 +
{{PerfectNavigation}}
 +
 +
<br />

Revision as of 01:50, 7 March 2022

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 available scripts, see the AI Script Compendium.

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 (impulse wakeup())
    • Triggers whenever the AI switches from inactive to active.
  • New Round (impulse game.newround())
  • Open: Buildings (impulse open.<building>())
    • Triggers whenever the window of the building is being opened (ex: Open: Arcade)
  • Key: 0-9, A-Z (impulse key.#())
    • Triggers whenever the 0-9 or A-Z key is being pressed (not numpad). (ex: Key: 0)

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, and any expression that returns a bool can be used as a condition.

Condition List:

  • Comparison: Bool (bool comparison.bool(bool: lhs, string: op_comp, bool: rhs)
    • Compares two boolean values based on the selected operator. Allowed operators are "=="/"=" (Equals), "!=" (Not Equal), "&&"/"&" (Both must be true), "||"/"|" (Either has to be true).
  • Comparison: Int/Double (bool comparison.<type>(type: lhs, string: op_comp, type: rhs)
    • Compares two <type> values based on the selected operator. Allowed operators are "=="/"=" (Equals), "!=" (Not Equal), ">", ">=", "<", "<=".
  • Comparison: String (bool comparison.string(string: lhs, string: op_comp, string: rhs)
    • Compares two string values based on the selected operator. Allowed operators are "=="/"=" (Equals), "!=" (Not Equal).
  • Factory: Is Processing (bool active(string: machine))
    • Returns true if the machine with ID Machine is currently processing items. (ex: Factory: Is Processing (Oven)). Always returns false outside the factory.
  • Mine: Has Layers (bool hasLayers())
    • Returns true if the current active mining tab can generate at least 1 layer. Always returns false outside the mine.
  • Museum: Fill Inventory (bool isfill())
    • Returns the current Fill Inventory state. Always returns false outside the museum.
  • String: Contains (bool contains(string: str, string: substr))
    • Returns true if the string str contains the string substr. (ex: "Catch" Contains "Cat")
  • Tower: Is Stunned (bool stunned())
    • Returns true if the tower is stunned and false if the tower is either not stunned or does not exist.
  • Town: Window Open (bool isopen(string: window))

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. Within one instance of a script, there is no way to execute more than one Action at a time (but by launching multiple copies of a script, this can be achieved).

Action List:

  • Basic: Goto (goto(int: line))
    • Jumps to line line. 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 (goto(int: line, bool: condition))
    • Jumps to line line in the current script if condition is True. First line equals 1.
  • Basic: Click (click(vector: pos))
    • Performs a mouse click at following location: pos.
  • Basic: Slider (slider(vector: where, double: value))
    • Sets the slider position where on the screen to value with 0 being the leftmost and 1 being the rightmost end.
  • Basic: Scrollrect (scrollbar(vector: where, double: horizontal, double: vertical))
    • Scrolls within a scrollable container at where to horizontal (horizontally) and vertical (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 (wait(double: value))
    • A simple wait function that stops the current script for a total of value seconds.
  • Basic: Wait Until (waituntil(bool: condition))
    • Stops the current script until condition becomes True.
  • Basic: Wait While (waitwhile(bool: condition))
    • Stops the current script as long as condition is True.
  • Basic: Execute (execute(string: script))
    • Executes the first script in the list which is named script without requiring an impulse. Conditions of the script called still have to be fulfilled. Executed scripts are put at the end of the script list, and because of this they (usually) will run their first action in the same frame, since the script list pointer is still on the calling script, earlier in the script list.
  • Basic: Execute (Sync) (executesync(string: script))
    • Executes the first script in the list which is named script and waits until the execution is completed. Conditions of the script still have to be fulfilled. As of 0.9.2, this has some bugs: If the conditions of the script are not fulfilled, executesync will wait forever without running anything. Also, if the executed script is killed with stop, execution will not continue.
  • Basic: Stop (stop(string: script))
    • Stops the execution of all scripts and script instances which are named script. Important bug/feature: If a script stops itself, the script list pointer is reset to the beginning, effectively giving everything before this script an "extra" cycle. Because scripts that have reached the end aren't cleaned up until the end-of-frame processing, this means that scripts on their last line (or that have jumped to 99) will re-execute their last line, which can cause bugs. This behavior is known as "Turbo Exec," since it can be used to build programs that execute much faster than the typical one-action-per-frame.
  • Global: Set (Double / Int / String)
    • Creates or changes the global variable "[EmptyX]" to contain the value [x.0 or if x has a decimal uses that instead] / [x] / string "[EmptyY]".
  • Global (Unset)
    • Deletes the global variable with the name "Empty".
  • Local: Set (Double / Int / String)
    • Creates or changes the local variable "[EmptyX]" to contain the value [x.0 or if x has a decimal uses that instead] / [x] / string "[EmptyY]".
  • Local: (Unset)
    • Deletes the local variable with the name "[Empty]".
  • Tower: Use (Instantly)
    • Orders the Tower to use the Modules at slot [x] where slot 1 refers to the module at the very top of the skill menu. Entering an invalid slot will do nothing.
  • Tower: Use (Position)
    • Orders the tower to use the module at slot [x] where slot 1 refers to the module at the very top of the skill menu at an offset of (X:[x], Y:[y])
  • 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
    • Digs up the tile at X: [x] and Y: [y] of the currently selected resource in the Mine with (0, 0) being the top left corner. Only works if the Mine window is active!
  • Mine: New Layer
    • Generates a new layer of the currently selected resource in the Mine. Only works if the Mine window is active!
  • Mine: Open Tab
    • Opens the mining tab at position [x]. Position 1 is the first tab (Orange) and position 12 is the last tab (Black).
  • Mine: Delete Cluster
    • Removes the asteroid cluster at list position [x] where 1 represents the first cluster in the list.
  • Factory: Try Craft
    • Tries to craft "[Item]" (T[X]) a total of [y.0 or if y has a decimal uses that instead] 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 [x.0 or if x has a decimal uses that instead] x [Item] (T[y]) 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
    • Tries to put [x.0 or if x has a decimal uses that instead] x [Item] (T[y]) into the trash can of the Factory. If too few items are present in the inventory and the crafting grid of the Factory then it will still try to remove as many as possible. Ignores the tier for items that don't have a tier.
  • Powerplant: Sell
    • Sells the Power Plant component at X: [x] and Y: [y] 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!
  • Tradingpost: Trade
    • Trades the offer at position [x] in the list of offers (first offer is at position 0) using [y.0 or if y has a decimal uses that instead] (0.15 = 15%) of the available input resources.
  • Museum: Fill Inventory
    • Sets the Fill Inventory button to the [T/F] state.
  • Museum: Combine
    • Combine Power Stones with the usual combine rules up to Tier [x] (<1 means no limit).
  • Museum: Transmute
  • Museum: Buy
  • Museum: Buy Market
  • Museum: Move
  • Museum: Delete
  • Museum: Delete All
AI-Script-Editor (Ingame)
AI-Script-Editor (In game)

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 requirements are 7.98actions-7, 7.988*conditions-12 and 7.9811*impulses-15 bytes, rounded up. The largest requirement takes effect - they're not added together.

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 3

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.797 × 10308.
int A number that does not allow decimal precision. Can be positive or negative. 20, 69, 420, -1029, 0 0 Ints range from -2147483648 to 2147483647
string An array of characters. Basically a way to format and use text. "meow", "hello", " ", "I am a text", "!BanBudE" "" 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 datatypes 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 Yes Yes - 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.