- Cached
- Space Engineers Sound Block - Image Results
- Space Engineers Sound Block Script
- Steam Workshop::Sound Block Mod Maker
- Space Engineers Sound Block Mods
Programming in Space Engineers is done with the Programmable Block which can be given scripts written in C# (pronounced C Sharp). This can be used to make autonomous mining drones, long-range player-killing torpedoes, automated welding arms for ship construction and much more.
- 1Introduction
- 2Available interfaces
- 3Example programs
Space Engineers is a sandbox recreation about engineering, development, exploration and survival in area and on planets. Players construct area ships, area stations, planetary outposts of assorted sizes and makes use of (civil and army), pilot ships and journey via area to discover planets and collect sources to outlive. Aug 13, 2016 Sound Block Mod Maker Test World: This is a world you can use to test the mods you create using the 'Space Engineers SoundBlock Mod Maker'. The 'Space Engineers SoundBlock Mod Maker' Is a small program that I created that takes care of all the difficult parts of creating a mod that adds sounds to the SoundBlock.
![Space Space](http://4.bp.blogspot.com/-qdk9tlmPUn8/VTiLxz2UbyI/AAAAAAAADGg/GE9XH9SJGHI/s1600/Space%2BEngineers.jpg)
Introduction
Editor access
Only one player can edit the same script at time. If someone else has an editor for the current block open and someone else tries to open that block's editor, a notification will be shown that the editor is already open.
![Space Engineers Sound Block Space Engineers Sound Block](https://i.ytimg.com/vi/XWp2oVLMxyY/hqdefault.jpg)
Main method
When the editor is opened for first time, void Main() method is present inside the code editor.This is entry point that will be called when executing script. If Main method is removed / renamed, the script will not run and you will be notified in the programmable block details area. Custom methods/variables can be defined and used, but only the Main method will be called without reference.
Variable lifetime and scoping
There are two types of variables for scripting:
- Local (inside the methods)
- these variables will keep their value only during execution of a method. Value will be 'lost' when the method ends.
- Global (outside the methods)
- these variables will keep their values during the lifetime of script. For example, if the variable needs to keep its value between separate runs of the script, it needs to be defined outside the methods.
After pressing 'Remember & Exit' or 'Remember' buttons, the previous script will be overwritten and all Global variables will be lost.
All variables, local and global except for the built-in Storage variable will lose their value or return to their default value when recompiling the code and between saved game loads.The Storage variable is unique in that it will store the data as a string for use between saved sessions and recompile.
Compiling
When the 'Check code' button is pressed, the code will be compiled and the result of the compilation will be shown.There are two steps of the compilation process:First the code inside editor is compiled by c# compiler for language errors.If there are any errors during compilation the following dialog is shown:It this case 'aaa' string is placed before Main method. This is the wrong language construction and the compilation failed.In the error dialog the Line number error and description of the error is shown.
After compilation, the code is checked for usage of disallowed namespaces and types. In case that check fails,the following dialog is shown:In this case System.IO.Directory was used to delete some directory. This is forbidden and error is shown that 'Not allowed type was used in script'.
![Space Engineers Sound Block Space Engineers Sound Block](http://media.moddb.com/images/articles/1/165/164414/screen1041.png)
If compilation and checks pass, a dialog is shown, confirming the checks passed, and the code is saved.
Script execution
Script can be triggered by the following means:
1. By pressing 'Run' button in terminal properties of programmable block.
2. By assigning terminal action and manually pressing the action button (1-9) while controlling the grid using cockpit, control station or remote control.
3. By pressing button on a button panel with assigned action 'Run'.
4. By a timer with assigned action 'Run'.
5. By another script in another programmable block in the same grid.
6. By antenna with assigned programmable block, when recieved message from another antenna. (see Antenna#Programming)
7. By the script itself, by assigning a value to Runtime.UpdateFrequency variable. In this case, no argument can be specified, however, you can use the following Main method signature: void Main(string argument, UpdateType updateSource) to gain acces to the information about what exactly triggered the script and so make the script 'know' if it was triggered by Update1, Update10, Update100 events or manually or whatever event was the reason of trigger execution.
Script is executed only on server even if it's triggered from client. If there is any exception during script execution, all clients will be notified in programmable block details area about failure.In case of exception during script execution, script will not run again unless User opens editor and change script.
Counting of instructions
Every time script is executed, every instruction of script is counted. If script executes more instruction than limit, execution is stopped and user is notified that script is too complex for execution. This prevents scripts to 'freeze' game.
Whitelist
The types and classes allowed in scripts are restricted. Refer to the Scripting Whitelist to see what you are allowed to use.
Available interfaces
Possible Actions
Cached
Currently only terminal actions can be triggered inside scripts. User can access terminal system for grid on which programmable block is located and trigger any terminal action on any block at grid.
Space Engineers Sound Block - Image Results
Block Classes (Action List)
Same block class for different SubTypeID
Some blocks have the same parent (e.g. in cubeblocks.sbc) and differs only by subtype (e.g. ). This means there is no distinction between these blocks in code.
Example of these blocks is the Cargo Container: there are 3 types of cargo containers in the game: small, medium and large. These three types differ only by the Subtype and Type is the same for them e.g. large cargo container id is:
Medium is:
And small is:
In this case there is only one class IMyCargoContainer for all types of cargo containers.
![Custom Custom](https://i.ytimg.com/vi/Hp5hoNgio6E/maxresdefault.jpg)
Example programs
Hello world
The standard Hello World program in Space Engineers can be written as such:
If this program is entered into a programmable block and run, it will result in 'Hello, world!' being displayed in the programmable block's interface on the lower right hand side of the screen.
Getting your position
This program will show the current GPS coordinates of your programming block's position in the world.
Checking a sensor
It's easy to get a sensor to open a door or trigger some other action even without any programming if you just place that action in the sensor's 'Setup actions' list. However, triggering an action when a sensor does not detect something is more difficult, and cannot be done with timer blocks. This program will automatically check a sensor every 10 ticks (working out to about 6 times per second) and close a door if the sensor does not detect anything. This can easily be applied to other purposes, like turning off drills when asteroids are not in sensor range.
For this script to work, the sensor must be named 'Door Sensor 1' and the door must be named 'Door 1'. If you configure the sensor to open the door, the door will automatically open when the player enters the sensor range and close when the player leaves the sensor range.
![Space Space](https://support.keenswh.com/spaceengineers/pc/attachments/1418?token=b107bca7d1d67e94bbba1b5c0f16a69f.jpg)
Introduction
Editor access
Only one player can edit the same script at time. If someone else has an editor for the current block open and someone else tries to open that block's editor, a notification will be shown that the editor is already open.
Main method
When the editor is opened for first time, void Main() method is present inside the code editor.This is entry point that will be called when executing script. If Main method is removed / renamed, the script will not run and you will be notified in the programmable block details area. Custom methods/variables can be defined and used, but only the Main method will be called without reference.
Variable lifetime and scoping
There are two types of variables for scripting:
- Local (inside the methods)
- these variables will keep their value only during execution of a method. Value will be 'lost' when the method ends.
- Global (outside the methods)
- these variables will keep their values during the lifetime of script. For example, if the variable needs to keep its value between separate runs of the script, it needs to be defined outside the methods.
After pressing 'Remember & Exit' or 'Remember' buttons, the previous script will be overwritten and all Global variables will be lost.
All variables, local and global except for the built-in Storage variable will lose their value or return to their default value when recompiling the code and between saved game loads.The Storage variable is unique in that it will store the data as a string for use between saved sessions and recompile.
Compiling
When the 'Check code' button is pressed, the code will be compiled and the result of the compilation will be shown.There are two steps of the compilation process:First the code inside editor is compiled by c# compiler for language errors.If there are any errors during compilation the following dialog is shown:It this case 'aaa' string is placed before Main method. This is the wrong language construction and the compilation failed.In the error dialog the Line number error and description of the error is shown.
After compilation, the code is checked for usage of disallowed namespaces and types. In case that check fails,the following dialog is shown:In this case System.IO.Directory was used to delete some directory. This is forbidden and error is shown that 'Not allowed type was used in script'.
If compilation and checks pass, a dialog is shown, confirming the checks passed, and the code is saved.
Script execution
Script can be triggered by the following means:
1. By pressing 'Run' button in terminal properties of programmable block.
2. By assigning terminal action and manually pressing the action button (1-9) while controlling the grid using cockpit, control station or remote control.
3. By pressing button on a button panel with assigned action 'Run'.
4. By a timer with assigned action 'Run'.
5. By another script in another programmable block in the same grid.
6. By antenna with assigned programmable block, when recieved message from another antenna. (see Antenna#Programming)
7. By the script itself, by assigning a value to Runtime.UpdateFrequency variable. In this case, no argument can be specified, however, you can use the following Main method signature: void Main(string argument, UpdateType updateSource) to gain acces to the information about what exactly triggered the script and so make the script 'know' if it was triggered by Update1, Update10, Update100 events or manually or whatever event was the reason of trigger execution.
Script is executed only on server even if it's triggered from client. If there is any exception during script execution, all clients will be notified in programmable block details area about failure.In case of exception during script execution, script will not run again unless User opens editor and change script.
Counting of instructions
Every time script is executed, every instruction of script is counted. If script executes more instruction than limit, execution is stopped and user is notified that script is too complex for execution. This prevents scripts to 'freeze' game.
Whitelist
The types and classes allowed in scripts are restricted. Refer to the Scripting Whitelist to see what you are allowed to use.
Available interfaces
Possible Actions
Cached
Currently only terminal actions can be triggered inside scripts. User can access terminal system for grid on which programmable block is located and trigger any terminal action on any block at grid.
Space Engineers Sound Block - Image Results
Block Classes (Action List)
Same block class for different SubTypeID
Some blocks have the same parent (e.g. in cubeblocks.sbc) and differs only by subtype (e.g. ). This means there is no distinction between these blocks in code.
Example of these blocks is the Cargo Container: there are 3 types of cargo containers in the game: small, medium and large. These three types differ only by the Subtype and Type is the same for them e.g. large cargo container id is:
Medium is:
And small is:
In this case there is only one class IMyCargoContainer for all types of cargo containers.
Example programs
Hello world
The standard Hello World program in Space Engineers can be written as such:
If this program is entered into a programmable block and run, it will result in 'Hello, world!' being displayed in the programmable block's interface on the lower right hand side of the screen.
Getting your position
This program will show the current GPS coordinates of your programming block's position in the world.
Checking a sensor
It's easy to get a sensor to open a door or trigger some other action even without any programming if you just place that action in the sensor's 'Setup actions' list. However, triggering an action when a sensor does not detect something is more difficult, and cannot be done with timer blocks. This program will automatically check a sensor every 10 ticks (working out to about 6 times per second) and close a door if the sensor does not detect anything. This can easily be applied to other purposes, like turning off drills when asteroids are not in sensor range.
For this script to work, the sensor must be named 'Door Sensor 1' and the door must be named 'Door 1'. If you configure the sensor to open the door, the door will automatically open when the player enters the sensor range and close when the player leaves the sensor range.
Compilation errors
This is a list (in progress) of known compilation errors and what causes them.
Space Engineers Sound Block Script
- Method name expected: The compiler found parentheses when it wasn't expecting them. You could be missing a method name before the parentheses, or you might be inappropriately using parentheses instead of square or curly brackets, depending on what you're trying to do.
See also
- MyGridTerminalSystem - Methods for getting object references to your various ship components.
- Programming Guide/Action List - Actions you can apply to objects via the Object.ApplyAction method. Also includes some of the object properties. Data appears incomplete as of March 19th, 2018.
External links
- [Guide] Programmable Block - C# 101 For Space Engineers - Basic intro to C# programming for Space Engineers.
- [Guide] Programmable Block - C# 102 for Space Engineers: Loops, Strings, and Other Things - Basic intro to using loops and strings in C#
- [Guide] Programmable Block - C# 103 for Space Engineers - Math Class - Basic intro to using the Math library in C#
- Programmable Block Inter-Grid Communication Guide - Using antennas to enable programming blocks to remotely communicate with each other.
- Continuous Running No Timers Needed - Configuring programming blocks to run automatically without needing to use a timer.
- Tutorial: Constructor And Save - Saving and reloading data
- C# Operators - C# language reference for all operators, such as and, or, greater than, less than, etc.
- Space Engineers ModAPI Documentation - Includes many API methods and properties which can be used by Programmable Blocks.
Setup:
Underground base, on one of the sides I drilled a hole down to 35 meters below ground, piped it up with conveyor blocks and built the walls.
The block in the middle of the floor was a conveyor junction, on top of it two pistons and on top of them another junction surrounded by blast doors and a gatteling turret.
Just below the entrance of the pit there are two timers, a sound block and a sensor, set to find sub-grids and set to trigger the timers according to if the grid is found or not.
On the entrance of the pit, hangar doors to cover it and two interior lights.
The idea:
Steam Workshop::Sound Block Mod Maker
When the pistons extend the turret will be detected by the sensor, timer 1 will trigger. opening the hangar doors, lighting the lights and playing a warning sound.
When the piston retract past certian area the sound will stop, lights off and the doors closing.
The problems:
1) Sound block won't always trigger when activated manually or by the timer, even when manually clicking the stop and play buttons.
2) When exiting the max sound distance and re-entering the sound stop and is not heard anymore, despite the block terminal window showing its still being played.
3) At times when the piston retract the sound block stop even before timer 2 trigger.
Space Engineers Sound Block Mods
Tested with both vanilla sounds and with modded sound packs.