Merlin of Mines - Space Engineers

A set of useful scripts for aspiring Space Engineers!

View on GitHub

Terminal Block Handler

The most basic block handler is the Terminal Block Handler, which supports any block that is a TerminalBlock. Almost all other BlockHandlers inherit from this and so also have these properties. The only exceptions to this are Displays and Inventories.

Default Primitive Properties:

Controlling Unsupported Block Types

It’s impossible to model all Block Types in Space Engineers, since you might have mods installed that add new block types that EasyCommands doesn’t know about. Luckily, since almost all blocks inherit from Terminal Block, you can control most of those block’s even if they don’t have an explicit handler of their own. So, if you find there’s a block type (which is a Terminal Block) without a block handler (including 3P block types from mods), you can get some control over it’s properties with this Block Handler.

Here’s a script to print out properties & values for an unsupported block:

set unknownBlock to "Unknown Block"
#Print a set of supported properties for the given blcok
Print $unknownBlock terminal properties

#Print out current property names and values
set myProperties to $unknownBlock terminal properties

set myOutput to "Unknown Block Name: " + unknownBlock + "\n\n"

for each i in 0 .. count of myProperties[] - 1
   myOutput+= "Property: " + myProperties[i] + ", Value: " + $unknownBlock terminal myProperties[i] property + "\n\n"

print myOutput

And a similar script for printing out available actions for an unsupported Block:

set unknownBlock to "Unknown Block"
#Print a set of supported actions for the given blcok
Print $unknownBlock terminal actions

#Print out current property names and values
set myActions to $unknownBlock terminal actions

set myOutput to "Unknown Block Name: " + unknownBlock + "\n\n"

for each i in 0 .. count of myActions[] - 1
   myOutput+= "Action: " + myActions[i] + "\n\n"

print myOutput

“Name” property

Gets or sets the CustomName of the given Terminal Block (the name you see in the Terminal menu).

This property can also be useful for getting a list of names for all blocks in a given selector:

set nameList to "My Turret" names
print "My Turret Names: " + nameList

You can also use this to rename all blocks in your grid with a unique prefix, like so:

set prefix to "[Base] "
set myTurrets to the turret names

#For each turret, if it isn't prefixed with my prefix, then add it
for each turretName in the turret names
  if turretName does not contain prefix
    set $turretName turret name to prefix + turretName

Careful using this, as if you have too many blocks you can easily get the Script Too Complex issue. If this happens, try getting block names for individual block types instead.

“Show” property

Gets or sets whether the given block is shown by default in the terminal menu. Useful for hiding individual blocks after you have created groups for them.

if any of "My Doors" are showing
  hide "My Doors"

“Enabled” property

Sets whether the block is turned on or off. This property is present for any block that you can enable or disable from the terminal block menu.

if "My Remote Control" is disabled
  enable "My Remote Control"

“Power” property

Identical to “enabled” unless overridden by the specific block handler.

power on the "Hydrogen Thrusters"
turn on the "Exterior Lights"

“CustomData” property

Gets or Sets the blocks CustomData field.

#Output your current program
print my data

#Delete your current program (do not actually do this).
set my data to ""

“DetailedInfo” property

Returns the detailed info of the block. DetailedInfo contains the text on the right hand site of the terminal menu.

set myInfo to "Battery" details split "\n"

#Output stored power
Print myInfo[6]

“Position” property

Returns the current position of the given block, in World Coordinates.

#Gets the current position of the programmable block
Print "Block Position: " + my position

#Gets the current position of the remote control block
Print "Remote Control Position: " + "My Remote Control" position

“Direction” property

This directional property returns a normalized vector representing the requested “direction” with respect to the block, in World Coordinates. In other words, if you add “my position” and “my forwards direction” together, you get a coordinate that is 1 meter in front of the block’s position.

This property is really useful for creating things like target coordinates, which can then be sent to other grids. Useful for “follow me” scripts or defining paths for other ships to follow.

Supported Directions:

set myPosition to my position
set myForwardsDirection to my forwards direction
set myDownwardsDirection to my downwards direction

set targetLocation to myPosition + 10 * myForwardsDirection + 20 * myDownwardsDirection

Print "Target Location: " + targetLocation

“Properties” Property

Print "My Properties: " + the "Test Piston" properties

“Property” Property

This property can get or set a given Terminal Property for the block. The attribute is expected to be a String representing the name of the property to be updated. When resolving what property to get or set, the resolved value is first compared against known reserved keywords which represent other properties. So, you can dynamically set Terminal Properties using this feature:

#These two commands are equivalent
set the "Base Antenna" range to 2000
set the "Base Antenna" "range" property to 2000

If the given block type does not have a property for the given keywords, then the block attempts to look up the SpaceEngineers property for that block by name. This enables you to get or set properties even if they do not have explicit property mappings. See “Controlling Unsupported Block Types” for more information.

“Actions” property

Print "My Actions: " + the "Test Piston" actions

“Action” Attribute Property

Applies the given action on all blocks in the given Selector. Actions do not have return values, so this is an update-only property.

#All of the following will work
tell the "Gatling Turrets" to apply the "ShootOnce" action
apply the "ShootOnce" action on the "Gatling Turrets"
apply the "Gatling Turrets" "ShootOnce" action

set myAction to "ShootOnce"
tell the "Gatling Turrets" to apply myAction action
apply myAction action on the "Gatling Turrets"
apply the "Gatling Turrets" myAction action

“Build” Property

Returns true if the terminal block is at full integrity, meaning it has all required components and is not damaged.

when "My Turret" is built
  print "Construction complete"

“Complete” Property

Same as Build. Returns true if the terminal block is at full integrity, meaning it has all required components and is not damaged.

when "My Turret" is finished
  print "Construction complete"

“Build Complete” Property

Same as Build. Returns true if the terminal block is at full integrity, meaning it has all required components and is not damaged.

when "My Turret" is finished being built
  print "Construction complete"

“Build Level” Property

Returns the effective build integrity of the block by returning the current build integrity of the block minus any damage the block has taken.

Print "Build Integrity: " + "My Turret" build level

“Build Limit” Property

Returns the maximum integrity of the block.

print "Max Integrity: " + "My Turret" build limit

“Build Ratio” Property

Returns the effective built ratio of the block as a value between 0 and 1 by returning the current build integrity of the block minus any damage the block has taken and then dividing by the blocks maximum integrity. This property is useful for getting the % built of any block.

Print "Build Ratio: " + "My Turret" build ratio

“Damage” Property

Returns the amount of damage a block has currently taken, including any Build Integrity that is currently missing. Effectively the damage will be the maximum integrity minus the current build level. If compared to a boolean, will return true if the damage is greater than 0.

if "My Turret" is damaged
  print "You shot at me!"

Print "Turret Damage: " + "My Turret" damage

“Damage Level” Property

Similar to Damage. Returns the amount of damage a block has currently taken, including any Build Integrity that is currently missing. Effectively the damage will be the maximum integrity minus the current build level. If compared to a boolean, will return true if the damage is greater than 0.

Print "Turret Damage: " + "My Turret" damage level

“Damage Limit” Property

Same as Build Limit. Returns the maximum integrity of the block, which is effectively the maximum amount of damage that the block can sustain before being destroyed.

print "Max Integrity: " + "My Turret" damage limit

“Damage Ratio” Property

Returns the effective damage ratio of the block as a value between 0 and 1, which is 1 - Build Ratio. This property is useful for getting the damage % of any block.

Print "Damage Ratio: " + "My Turret" damage ratio