Make your own custom scripts without writing a single line of code.
Visual Script Builder allows you to create Space Engineers scripts with a user interface. You don't need to know anything about programming. Just enter the name of the block you want to control and choose what to do with it. Chain logic statements together to create complex behaviors.
A large number of Space Engineers players are unable to utilize programming. The scripting documentation is poor, and the in-game editor doesn't provide any help. Many people are unfamiliar with coding, and C# in Space Engineers doesn't make for a simple beginner language. There are scripts available on the Steam Workshop, but those rarely work for custom applications.
I developed this tool to let anyone capable of playing Space Engineers write their own custom scripts. I tried to make it as feature-rich as possible while still being easy to use.
Item Precision bugfix
Fixed issue where Item Precision was causing script compilation to fail.
Run Frequency, Item Precision, bugfixes
Added Frequency to Script Settings to allow script to be run every 1, 10, or 100 ticks.
Added Item Precision to Script Settings to control decimal places when displaying item counts on LCD Panels.
Fixed bug with extra field for Oxygen Tank always returning 0.
Modified Variable logic so quotes are not required around string fields. Variable names are auto-detected.
Performance improvements, Piston position, seat taken, bugfixes
Cut loading times from Load Line by around half.
General performance increase for larger scripts.
Generate Script button will replace Copy Script to Clipboard button to keep from generating the entire script so often. When the button is clicked, or the script has to be generated for the interface to update properly, the Copy Script to Clipboard button returns. Just clicking Generate Script won't copy. You'll have to click again once the script has been generated.
Added position to Piston.
Added IsUnderControl to all types of Cockpits to tell whether a seat is occupied.
Added more controls for Wheel Suspension.
Updated the overview to make it more obvious that sections are clickable, and automatically scroll to the appropriate chunk.
Added highlight to Block Types that are already part of the script.
Added suggestions for Block Name and Group Name.
Fixed bug with error messages sometimes appearing on wrong chunks.
Fixed bug causing hide/show not to save and load correctly for large scripts.
New status fields, error checking option
Added new Status field for Air Vents, Doors, and Connectors.
Added Current Output to Batteries.
Added LockMode field to Landing Gear which returns string ("Locked", "Unlocked", "ReadyToLock").
Added 'argument' to list of variables for use on LCD panel.
Added Allow Missing Blocks option to settings.
Updated footer text.
Using Variables makes more sense
Added IsActive field to Sensors, which returns true when the Sensor is detecting a player/object/etc.
Added Max Output and Current Output to Small and Large Reactors.
Tweaked script error output to clear the errors from the Programmable Block's Detailed Info when the script runs successfully.
Overhauled User Variable logic to be independent of Blocks. Variables added to the Affect buttons, which hides the Block Type, Block Name, and Block Group options when selected. Older saves that use variable logic in the same chunks with block logic will need to be updated. These saves will populate all the same information, but the user must select between Variable and Single/Multiple blocks. Both cannot be applied in the same chunk.
More blocks, arguments for Programmable Block, images on LCD Panels, changing Antenna names, bugfixes
Added Hydrogen Tank and Conveyor Sorter blocks.
Allows name changing for Antennas.
Block type change pop-up only appears after data has been entered.
Fixed broken All Blocks of Type - LCD Panel.
Added Textures/Images to LCD Panels.
Added Arguments to Programmable Blocks.
Block groups, help system, code validation, advanced calculations, more blocks
Added the ability to select blocks by Group.
Added integrated help system - just click the question marks.
Code now displays useful error messages in the programmable block's detailed info.
Added ability to run arbitrary code within LCD/Text Panels to allow complex calculations.
Added Advanced Rotor and Gatling Gun blocks.
Added Angle (0 - 6.28) and Angle in degrees (0 - 360) to Rotor and Advanced Rotor.
Added confirmation screen before deleting a chunk.
Added confirmation screen before changing block type, which clears out data.
Removed unnecessary Grid Block Name field.
Added fancy new banner and footer.
Other miscellaneous functionality added.
Block functionality updates, ammo, bugfixes
This update adds functionality to some incomplete blocks, and adds ammo as an item.
Added inventory and actions for Reactors.
Weapons now have inventories for ammo.
Added lock state for Landing Gear.
Added functionality for Thrusters.
Changed variables to use brackets instead of parenthesis in LCD Panels.
Other miscellaneous functionality added.
Firefox support, bugfixes, user variable logic
This update changes the way + and - work for adding to and subtracting from properties. When subtracting a variable from a property, you must now use -- instead of - due to ambiguity. Some properties can be set to negative numbers, which is done using a single minus. Plus has been modified to work the same way; ++ is required to add variable's value to a property. Saving a variable still works as it used to, using single minus and single plus to subtract or add to a variable in the save box.
Fixed a problem with IF All Blocks of Type and IF Any Blocks of Type that caused them not to compile.
Added User Variables section to the bottom of each logic chunk. This can be used to check a value of a variable, or set/increment a variable. Incrementing variables must be done with double plus or double minus.
Added Functional Block as the first block in the block list. This represents any block that can be turned on or hacked. It is not recommended to use with Single Block logic type selected. As suggested by /u/sumguy720, it is designed to check if any blocks are being hacked.
- Build if-then-else logic statements visually
- Choose specific logic by block type
- Apply logic to single or multiple blocks
- Create variables from block attributes and fields
- Save/load scripts to edit later
- Text panel/LCD output with variables
- Item and inventory management
- Variable logic/math
Features coming soon
- Block counts
- This utility is designed to work in Google Chrome. I cannot guarantee functionality in any other browsers.
- This utility works within a single page. Do not click the back button to undo a change. You will lose your work!
- Refreshing the page will clear everything. You will lose your work!
- Keep in mind that as you create your script, the page is updated automatically. You will not need to "Apply" your logic to add it to the script. As you add logic chunks to the page, those logic chunks are used in the script. Removing them from the page removes them from the script.
How It Works
In Visual Script Builder, everything is driven by logic chunks. One logic chunk can either check a condition (e.g. If Light X is ON), or apply an action (e.g. Turn Light Y ON). You can insert logic chunks and remove logic chunks at any point in the script. There is no limit to the number of logic chunks you can use. Each logic chunk consists of the logic type, the in-game Space Engineers block it applies to, and the in-game block's data.
A logic chunk that starts with IF logic is called an IF block or an IF logic chunk.
A logic chunk that starts with DO logic is called a DO block or a DO logic chunk.
The logic type can be chosen via the logic chunk's first row of buttons. The six logic types are explained below.
|IF||condition (if)||Check a condition.|
|DO||action (do)||Perform an action or set a value.|
Following an IF logic chunk, works as a continuation of the IF logic chunk. e.g. IF (a AND b). Can be chained together. e.g. IF (a AND b AND c). Can also be combined with OR. e.g. IF (a AND b OR c).
Following a DO logic chunk, works as a continuation of the DO logic chunk without leaving the previous IF block. e.g. IF (a), DO (b AND c). b and c both happen when condition a is met. Using DO instead of the AND would always perform c and would only perform b when condition a is met. e.g IF (a), DO (b). DO (c).
|OR||condition (if)||Following an IF logic chunk, works as a continuation of the IF logic chunk. e.g. IF (a OR b). Can be chained together. e.g. IF (a OR b OR c). Can also be combined with AND. e.g. IF (a AND b OR c).|
|ELSE IF||condition (if)||
Works just like an IF logic chunk, but must be placed after a DO logic chunk that follows an IF logic chunk. Checks a condition only when the previous IF condition was not met. e.g. IF (a) DO (b) ELSE IF (c) DO (d). When condition a is not met, condition c will be checked. If condition c is met, d will happen. However, if condition a is met, b will happen and c will not be checked.
Can be used following another ELSE IF's DO logic.
|ELSE DO||action (do)||Performs an action or sets a value only when the previous IF failed. e.g. IF (a) DO (b) ELSE DO (c). When condition a is met, b will be executed and c will not. When condition a is not met, b will not be executed and c will be executed.|
Sometimes, certain logic types will not be accessible. The button becomes greyed out depending on previous logic. For example, on the first block, you cannot choose AND because that does not start a logic statement correctly. You cannot choose OR to follow a DO logic chunk. (DO a OR b does not make sense.) ELSE IF and ELSE DO cannot be used unless there has been a previous IF statement.
Here are some examples:
Create simple logic using the IF button on the first logic chunk, and the DO button on the second logic chunk:
IF Door is OPEN, SET Interior Light ON
Using IF followed by an AND logic chunk will create logic like this:
IF Door is OPEN AND Interior Light is ON
Using DO followed by an AND logic chunk will create logic like this:
SET Door CLOSED AND SET Interior Light OFF
We can combine the two using IF, AND, DO, AND to create logic like this:
IF Door is OPEN AND Interior Light is ON, SET Door CLOSED AND SET Interior Light OFF
If this is a bit confusing, try out the simple tutorial toward the bottom of this page.
Beneath the row of logic buttons, you can see three choices for block type. Single Block, All Blocks of Type, and Any Blocks of Type. They allow you to decide if the condition or action will be applied to one or more blocks.
Select Single Block to set values or get fields for one block. Optionally include a name for the block (e.g. "Interior Light 6"), or leave it blank to default to the block's default name (e.g. "Interior Light" for an Interior Light block).
Select All Blocks of Type to set values or get fields for all blocks of the selected type. Optionally include a name to filter by (e.g. "Station" to search only blocks that have "Station" in their name), or leave it blank to get all blocks of the type. You can then apply actions or set values for all the blocks that you have chosen. When using IF logic, All Blocks of Type allows you to check a condition for each block you've selected. You can check that all of your doors are shut, or that all of your batteries are recharging.
Any Blocks of Type works similarly to All Blocks of Type, but only allows checking conditions. You cannot set a value for Any Blocks of Type. It can be used with IF logic to check if any doors are open, or if any Air Vents are not pressurized, for example.
In the dropdown menu, you can select the type of in-game block you want to check or modify. Changing this selection will clear all fields for the logic chunk that had been filled out, and replace them with the appropriate fields for the newly selected block type. You can choose to give the block a name, which will select the block of the chosen type that has the custom name that you entered. When using All/Any Blocks of Type, your text entered is used as a filter. Only the blocks which contain the entered text will be used.
For example, if you want to get only Batteries that have a name including "Station", you can enter "Station" in the block name field, and choose All Blocks of Type. This will select only the Batteries that have "Station" somewhere in their name. It will get Batteries named "Station Battery 5" and "Battery 3 [Station]" but would not get a battery named "Battery 2", because it does not include the filter text.
You can also enter the name of a group, which will only include blocks that are in the specified group.
Choose specific logic by block type
After choosing a block, you are shown only the fields and properties you can get or set for that block. You don't need to know field, property, or action names in order to check or modify them. The logic you choose will also affect which fields are shown. For example, when the logic is IF, you won't see the choice to open a door. You would only see the option to check if the door is open. To open the door, you'd have to choose DO, and apply the appropriate action.
For IF logic chunks, enter a value in one or more of the boxes to check that the field is equal to the value you entered. The If button next to the field name will become selected, indicating that the field will be used. If you decide not to use the field, you can delete the contents of the box or click the If button to deselect it. The field will only be applied when the If button for that field is selected. The operator (equals sign) can be clicked to change the type of comparison. For numbers, you can use equal, not equal, greater than, greater than or equal, less than, and less than or equal. For other types, you can only use equal and not equal.
DO logic chunks work similarly, but they set a property to the value entered in the box. When you enter a value for a property, the Set To button will become selected. This means that the property will be set to the value entered. Actions have no values to enter, so applying an action is as easy as choosing which action to apply. Multiple values can be set and multiple actions applied in one logic chunk.
Create variables from block attributes and fields
Variables can be created to store values by entering a name in the Save As box. There is one box for each value that can be saved, and these boxes only become available when using DO logic.
After a variable has been set, it can be used in IF logic chunks to compare a value against the variable. When clicking on an input box for a field in an IF logic chunk, a list of the variables that have been created will be shown below, and can be selected. Note that the type of the field is important. If a boolean (true/false) variable was created, it will only be shown as an option for boolean fields.
Saved variables can be used in DO logic chunks to set a property to a variable's value.
You can add to numeric variables using a plus sign (+), or subtract from them using a minus sign (-). If you wanted the total stored power in all of your batteries, you could add each Stored Power value together by choosing All Blocks of Type Battery, then saving the Stored Power as +totalpower to create a variable totalpower, which would have the sum of all Stored Power values from your Batteries.
When writing the text you want displayed on an LCD panel, you can use any variables that you created in your script by surrounding them with brackets. For example, if you saved a variable called totalpower, you could display its value on an LCD panel by writing [totalpower]. This can be combined with any other text, or any other variables. Total Power: [totalpower] would display Total Power: 3.00MW. See additional information about using LCD panels below.
Item and inventory management
You can transfer items between blocks that have inventories. Blocks with inventories, such as the Refinery, Assembler, or Cargo Containers have their inventories shown with a list of all valid items. Refineries will have two inventories, one for the ore, and one for the resulting ingots.
Using an IF logic chunk allows you to check the quantity of items in an inventory. For example, you could check that there is no ore in a Refinery, then use a DO logic chunk to add more ore to the Refinery.
Using a DO logic chunk allows you transfer items to or from another inventory. To change between Send [x] to [inv] and Take [x] from [inv], click the word to or from. This will toggle between the two.
When sending or taking items, the amount field accepts decimal numbers (ex. 10.4), numeric user-defined variables (ex. oreAmount), and percentages (ex. 10%). You can even take a percentage of a variable (ex. oreAmount%). A note about using percentages, the percent amount is based on the quantity at the time of transfer. So if you transfer 50% of the Stone in an inventory to another inventory, then transfer 50% again, the second transfer sends 50% of what's left (25% of the original). If you want to send 50% to one place and 50% to another, you'll need to first send 50% and then send 100%.
Quantity of an item can be saved as a variable using a DO logic chunk as well.
In order to send items to an inventory or take items from an inventory, you must give the other inventory a name. This is done by typing a name into the the Inventory line of the other block. If the other block is not otherwise used, you can create a DO logic chunk at the top of your script for that block, give the correct inventory a name, and leave all other fields blank for that logic chunk. This will define the inventory without applying any actions or changing any properties (though you can also apply actions or change properties if you want).
Let's create a script that pulls Iron Ore from a Small Cargo Container and puts it into a Refinery. You need two DO blocks for this script; one for the Small Cargo Container, and one for the Refinery. For this example, we will send the ore to the Refinery. Create a DO block for the Refinery first. In the Refinery's first inventory, enter a name for the inventory (ex. refinv). Now create a DO block for the Small Cargo Container. In the Small Cargo Container's inventory, find Iron Ore. You'll see a button Send, an input field, the word to and another input field. The first input is the amount, which you can leave blank to send all. The second input is the inventory you're sending the items to. When you click that box, the refinv inventory you named earlier will be suggested. Click on the name to choose that inventory. The Iron Ore line should look like this: Send (blank) to refinv. Your script is complete. When it is run, it will attempt to send all Iron Ore from the Small Cargo Container to the Refinery's first inventory (for ores). Note that this same result could be achieved by reversing these blocks, giving the Small Cargo Container inventory a name, and applying Take (blank) from smallcargoinv in the Refinery's Iron Ore option in its first inventory.
Multiple different types of items can be sent and taken within a single logic chunk.
Copy script to clipboard with one click
Don't worry about highlighting and copying, just click the button to copy your entire script to the clipboard and paste it into the editor in Space Engineers.
Save/load script to edit later
The result script has a line at the top which represents your entire script. If you decide you want to change something about your script after it's complete, you can copy that weird looking line into the Load box to continue from where you left off. Be sure to copy the entire line, starting with //. It will likely be longer than the width of the in-game editor, so make sure you copy from the start of the second line. If you aren't sure you got it all, you can use CTRL-A to highlight your entire script, then copy and paste it into a Windows text editor. From there you should be able to copy the entire load line.
On the left hand side of the page is an Overview box. It shows the simplified logic structure of the script. Moving the mouse over the lines in this overview will highlight the corresponding logic chunks in the script creator. Clicking a line will scroll to the chosen logic chunk. The Overview box will remain on the left hand side of the page.
LCD & Text Panel Formatting
Using variables on an LCD panel can be done by placing brackets around a variable name. This will display the variable's value on the LCD panel.
For example, if we create a variable called power that has a value of 3.00MW, we can write:
Total Power: [power]
to display it on an LCD panel as:
Total Power: 3.00MW
Boolean (True/False) Variables
It's possible to display different text based on the value of a boolean (true/false) variable. We can do this using a Ternary Operator, which takes three inputs; the boolean variable name, the text to display if the variable is true, and the text to display if the variable is false. The format for the Ternary Operator is:
As you can see, our variable (here named variableName) is followed by a question mark (?), the text to display when true (trueText), a colon (:), and the text to display when false (falseText). For use on the LCD panel, we must enclose this whole string in brackets. In a more realistic scenario, we might want to display ON when our Reactor is on, and OFF when our Reactor is off. We can create a boolean variable called reactorOn for the Reactor's On/Off state by typing a new variable name (reactorOn) into the Save As box for the OnOff property of the Reactor. For this property, true means the reactor is on. To get the text to display correctly, we can type the following into an LCD panel.
The Reactor is [reactorOn?ON:OFF]
When we run this script, the text will display either
The Reactor is ON
The Reactor is OFF
depending on the state of the Reactor.
As of Update 1.0.3, it's also possible to do calculations right inside the text of the LCD panel. This allows you to display your power percentage. Mathematically, power percentage is:
100 x current power / total power
To do more complex calculations, you can use double brackets. This escapes the text string, and executes any code you type as though you were writing code in the in-game script editor.
For example, with the variables currentpower and totalpower populated correctly, this would display the power percentage:
Power Percentage: [[100 * currentpower / totalpower]]%
This can cause your script not to compile if you don't use the correct C# syntax. There is no error checking in VSB to ensure the code you typed is valid.
Let's get started creating a basic script to toggle an Interior Light on/off.
Click the button in VSB to create a New Script.
Click the + Add New Block button. This will add a new logic chunk to work with.
You'll see a few buttons, and some are already selected. The first row of buttons contains logic choices. For the first logic chunk, there are only two logic choices available; IF and DO.
Make sure the DO button is selected. This will give us the option to set properties of our logic chunk (such as setting the radius for a light), and to perform actions (such as turning a light on or off).
The second row of buttons lets you choose to set the properties and apply the actions to a Single Block, All Blocks of Type, or Any Blocks of Type. For now, leave this set to Single Block.
Use the Block Type dropdown menu to choose the type of block you want to work with. Click it, and a warning will show up to let you know you may lose work by changing the block type. Press the red Yes button to unlock the Block Type menu, then click the menu again and choose Interior Light.
The Block Name box is where you enter the name of the Space Engineers block you want to work with. If this is left blank, the default value will be used for the chosen block type. Leave this blank.
The Group Name box lets you choose to only get blocks from one specific group. If this is left blank, all blocks can be used. Leave this blank.
You'll now see the available properties and actions for the Interior Light block. Here, you can specify the values to set for each property, and choose which actions to apply. Select the Apply Action button to the right of action OnOff.
That's it! You're now ready to try the script out. Click the Copy Script To Clipboard button, and paste the code into a Programmable Block in Space Engineers. Running the code will toggle on/off an Interior Light with the name "Interior Light".
The load line for the script shows up on the first line of the script output. It should look something like this:
You can load your script by pasting that load line into VSB when you first open the page.
If you need an overview on how to use a Programmable Block in Space Engineers, read the section below.
How to Use a Programmable Block
If you already know the basics of getting a script to run in Space Engineers, you can skip this section.
In Space Engineers, create a Programmable Block. Go into the Programmable Block's menu and click Edit. Delete everything in the editor and paste in your script. CTRL-C and CTRL-V work in the editor. Click Check Code to check the code for errors, then click Remember & Exit to save. Be careful, as using ALT-TAB to switch out of Space Engineers will revert your script to the last saved script. It is easy to lose your changes.
To run the script, open the Programmable Block's menu and click Run. You can also assign this action to your toolbar in a ship, or to a button panel by dragging the Programmable Block to the bar and choosing Run with default argument.
If you want your script to be run constantly (for example, waiting for a door to open and triggering the lights to turn on) you can use the Frequency dropdown in the Script Settings menu. It will automatically run your script every 1, 10, or 100 ticks. There are 60 ticks per second in-game. This feature was introduced in version 1.0.8, but can cause issues when trying to use Arguments in the Programmable Block. With older versions, or to avoid issues with Arguments, you have to use a timer block. Create a Timer block and set the Trigger Delay to 1 second. Click Setup Actions, and drag your Programmable Block to the first space on the bar. Again, use Run with default argument. Then drag your Timer block to the next space on the bar and choose Start. Now start the Timer block, and your script will be executed every second.
If your script has an error, possibly due to a block name being incorrect, you'll see an error in the Programmable Block's detailed info. You may need to open the script editor and save the script again before re-running.
If you have any questions or need any help, send me a message on reddit. I'll try to get back to you as soon as I can.