Space Engineers Scripts

Here you can copy various scripts that can be used in Space Engineers’ Programmable Block.

For additional “Actions”, visit the official Space Engineers Wiki

This section includes 11 examples that can be copied straight into a Programmable Block in Space Engneers. Do Note that you may need to rename certain blocks in game for the scripts to work. Follow the comments indicated with “\\” at the beginning as they will indicate what will need to be changed.

Each example increases in complexibility, so try and do them in order if you are inexperienced.

These examples may not work if Space Engineers updates any Actions or Sytax. If you find that any of these examples does not work, please Contact Us.

  • 1 – Print text to the Debug Panel
  • 2 – Print text to a LCD Display named “TutorialLCD”
  • 3 – Print text to a LCD Display named “TutorialLCD” when the game is saved
  • 4 – Control a Rotor named “TutorialRotor”
  • 5 – Control Multiple Rotors using 1 script
  • 6 – Control a Piston named “TutorialPiston”
  • 7 – Control a Thruster named “TutorialThruster” (Works will all Thruster types)
  • 8 – Change Interior Light Colour depending on Sensor State
  • 9 – 4 Digit Combination Lock – Activate a Timer Block
  • 10 – Airleak Detection and Timerblock Trigger
  • 11 – Change colour of all Interior Lights in a group depending on the state of all Airtight Hangar Doors in a group

The Scripts are demoed in a few videos on YouTube. I explain how each script works in full detail:


Example 1 – Print text to the Debug Panel

public void Main(){
	//Display "Hello Universe" to the Debug Panel
	Echo ("Hello Universe");
}

Example 2 – Print text to a LCD Display named “TutorialLCD”

public void Main(){
	//Set your text as a string
	string MyText = "Hello Universe";
	//Find the LCD and assign it to ABCDEFG
	IMyTextPanel ABCDEFG = (IMyTextPanel)GridTerminalSystem.GetBlockWithName("TutorialLCD");
	//Write "Hello Universe" to the LCD
	ABCDEFG.WriteText(MyText);
}

Example 3 – Print text to a LCD Display named “TutorialLCD” when the game is saved

public void Save(){
	//Set your text as a string
	string MyText = "Hello Universe";
	//Find the LCD and assign it to ABCDEFG
	IMyTextPanel ABCDEFG = (IMyTextPanel)GridTerminalSystem.GetBlockWithName("TutorialLCD");
	//Write "Hello Universe" to the LCD
	ABCDEFG.WriteText(MyText);
}
void Main(){
}

Example 4 – Control a Rotor named “TutorialRotor”

void Main(string argument){
	//Block Declarations
	//Look for a rotor called "TutorialRotor" and assign it to "MyRotor"
	IMyMotorAdvancedStator MyRotor = (IMyMotorAdvancedStator)GridTerminalSystem.GetBlockWithName("TutorialRotor");
	//Logic (Only need to change the numbers at the end)
	MyRotor.Torque = (float)100;
	MyRotor.BrakingTorque = (float)50;
	MyRotor.TargetVelocityRPM = (float)10;
	MyRotor.LowerLimitDeg = (float)0;
	MyRotor.UpperLimitDeg = (float)180;
}

Example 5 – Control Multiple Rotors using 1 script

void Main(string argument){
	//Block Declarations
	IMyMotorAdvancedStator RotorX = (IMyMotorAdvancedStator)GridTerminalSystem.GetBlockWithName("RotorX");
	IMyMotorAdvancedStator RotorY = (IMyMotorAdvancedStator)GridTerminalSystem.GetBlockWithName("RotorY");
	//Logic (Only need to change the numbers at the end)
	RotorX.Torque = (float)100;
	RotorX.BrakingTorque = (float)50;
	RotorX.TargetVelocityRPM = (float)10;
	RotorX.LowerLimitDeg = (float)0;
	RotorX.UpperLimitDeg = (float)180;
	RotorY.Torque = (float)100;
	RotorY.BrakingTorque = (float)50;
	RotorY.TargetVelocityRPM = (float)10;
	RotorY.LowerLimitDeg = (float)0;
	RotorY.UpperLimitDeg = (float)180;
}

Example 6 – Control a Piston named “TutorialPiston”

void Main(string argument){
	//Block Declarations
	IMyPistonBase PistonX = (IMyPistonBase)GridTerminalSystem.GetBlockWithName("TutorialPiston");
	//Logic
	PistonX.Velocity = (float)1;
	PistonX.MinLimit = (float)0;
	PistonX.MaxLimit = (float)5;
}

Example 7 – Control a Thruster named “TutorialThruster” (Works will all Thruster types)

void Main(string argument){
	//Block Declarations
	IMyThrust ThrusterX = (IMyThrust)GridTerminalSystem.GetBlockWithName("TutorialThruster");
	//Logic
	ThrusterX.ThrustOverride = (float)1100000;
	//Disabled = 0 Max = 1100000
	//Action
	ThrusterX.ApplyAction("OnOff");
	//Switches between On and Off
}

Example 8 – Change Interior Light Colour depending on Sensor State

public Program(){
	Runtime.UpdateFrequency = UpdateFrequency.Update10;
}
void Main(string argument){
	//Find the Sensor called "ZoneSensor"
	IMySensorBlock ZoneSensor = (IMySensorBlock)GridTerminalSystem.GetBlockWithName("ZoneSensor");
	//Find the Interior Light called "ZoneInteriorLight"
	IMyInteriorLight ZoneInteriorLight = (IMyInteriorLight)GridTerminalSystem.GetBlockWithName("ZoneInteriorLight");
	// logic
	if(ZoneSensor.IsActive == true){
		//If the Sensor is Active, set the Colour to Red
		ZoneInteriorLight.Color = new Color(255, 0, 0);
		//(R, G, B) values can be anywhere between 0-255
	}
	else {
		//If the Sensor is Not Active, set the Colour to Green
		ZoneInteriorLight.Color = new Color(0, 255, 0);
		//(R, G, B) values can be anywhere between 0-255
	}
}

Example 9 – 4 Digit Combination Lock – Activate a Timer Block

//User Set Combination e.g. 4321
int C1 = 4;
int C2 = 3;
int C3 = 2;
int C4 = 1;

//Function
int W = 0;
int X = 0;
int Y = 0;
int Z = 0;
string LCDDoorLockText = "x.x.x.x";
public Program(){
	//Run the code in a loop 10 times a second
	Runtime.UpdateFrequency = UpdateFrequency.Update10
}
	public void Main(string argument){
		//Look for the Button Panel Run Arguement
		switch (argument){
			case "BPDL1":
			//Increment the 1st digit by 1
			W++;
			RunDoorLockSequence();
			break;
			case "BPDL2":
			//Increment the 2nd digit by 1
			X++;
			RunDoorLockSequence();
			break;
			case "BPDL3":
			//Increment the 3rd digit by 1
			Y++;
			RunDoorLockSequence();
			break;
			case "BPDL4":
			//Increment the 4th digit by 1
			Z++;
			RunDoorLockSequence();
			break;
		}
		//Main function for checking the script parameters
		public void RunDoorLockSequence(){
			//Look for the Timer block and assign it a name
			IMyTimerBlock Timer_DoorLock_Start = (IMyTimerBlock)GridTerminalSystem.GetBlockWithName("Timer_DoorLock_Start");
			//Look for the LCD Panel and assign it a name
			IMyTextPanel LCDDoorLock = (IMyTextPanel)GridTerminalSystem.GetBlockWithName("LCDDoorLock");
			//Check if any of the digits exceed 9 and reset them back to 0
			if(W > 9){
				W = 0;
			}
			if(X > 9){
				X = 0;
			}
			if(Y > 9){
				Y = 0;
			}
			if(Z > 9){
				Z = 0;
			}
			//Check if the user entered combination matches the set combination
			if((C1==W)&&(C2==X)&&(C3==Y)&&(C4==Z)){
				//Reset all digits back to 0
				W = 0;
				X = 0;
				Y = 0;
				Z = 0;
				//Activate the Timer Block
				Timer_DoorLock_Start.ApplyAction("TriggerNow");
			}
			//Set the String for the LCD Display
			LCDDoorLockText = W + "." + X + "." + Y + "." + Z;
			//Write the above String into the LCD
			LCDDoorLock.WriteText(LCDDoorLockText);
		}
	}

Example 10 – Airleak Detection and Timerblock Trigger

// Set the run Frequency
public Program(){
	Runtime.UpdateFrequency = UpdateFrequency.Update100;
}
	int Change = 0;
	void Main(string argument){
		// block declarations
		IMyAirVent AirVent_ALD = (IMyAirVent)GridTerminalSystem.GetBlockWithName("AirVent_ALD");
		IMyTimerBlock Timer_ALD_Start = (IMyTimerBlock)GridTerminalSystem.GetBlockWithName("Timer_ALD_Start");
		IMyTimerBlock Timer_ALD_Stop = (IMyTimerBlock)GridTerminalSystem.GetBlockWithName("Timer_ALD_Stop");
		// logic
		if(AirVent_ALD.CanPressurize == false){
			if(Change == 0){
				Timer_ALD_Start.ApplyAction("TriggerNow");
				Change = 1;
			}
		}
		else {
			Timer_ALD_Stop.ApplyAction("TriggerNow");
			Change = 0;
		}
	}

Example 11 – Change colour of all Interior Lights in a group depending on the state of all Airtight Hangar Doors in a group

public Program(){
	//Run the code every 10 Game Ticks
	Runtime.UpdateFrequency = UpdateFrequency.Update10;
}
//Set the Variables
int TotalWarfareHangarDoor = 0;
int TotalWarfareHangarDoorClosed = 0;
void Main(string argument){
	//Find a group called "WarfareHangarDoor" and get a list of Warfare Hangar Doors inside that Group
	IMyBlockGroup HangarDoorTestGroup = GridTerminalSystem.GetBlockGroupWithName("WarfareHangarDoor");
	//Change to the name of the group of Warfare Hangar Doors e.g. WarfareHangarDoor
	List<IMyAirtightHangarDoor> WarfareHangarDoor = new List<IMyAirtightHangarDoor>();
	HangarDoorTestGroup.GetBlocksOfType(WarfareHangarDoor);
	//Count how many Warfare Hangar Doors are in the "WarfareHangarDoor" Group and print to the Debug Panel
	TotalWarfareHangarDoor = WarfareHangarDoor.Count;
	Echo ("Total Warfare Hangar Doors" + TotalWarfareHangarDoor);
	//Find a group called "HangarInteriorLight" and get a list of Interior Lights inside that Group
	IMyBlockGroup HangarInteriorLightGroup = GridTerminalSystem.GetBlockGroupWithName("HangarInteriorLight");
	//Change to the name of the group of Hangar Interior Lights e.g. HangarInteriorLight
	List<IMyInteriorLight> HangarInteriorLight = new List<IMyInteriorLight>();
	HangarInteriorLightGroup.GetBlocksOfType(HangarInteriorLight);
	//As there can be many Warfare Hangar Doors in a Group, the code will check each door to see what state it is in
	foreach(var HangarDoorTestblock in WarfareHangarDoor) {
		//Check to see if the current Warfare Hangar Door on the list is Closed
		if(HangarDoorTestblock.Status == DoorStatus.Closed) {
			//If the Warfare Hangar Door is closed, add 1 to TotalWarfareHangarDoorClosed
			TotalWarfareHangarDoorClosed = TotalWarfareHangarDoorClosed + 1;
			//We don't want the TotalWarfareHangarDoorClosed to exceed the total amount of Warfare Hangar Doors in our group so we subtract 1 if so
			if(TotalWarfareHangarDoorClosed > TotalWarfareHangarDoor){
				TotalWarfareHangarDoorClosed = TotalWarfareHangarDoorClosed - 1;
			}
		}
		//If the Warfare Hangar Door is NOT closed, subtract 1 to TotalWarfareHangarDoorClosed
		else {
			TotalWarfareHangarDoorClosed = TotalWarfareHangarDoorClosed - 1;
			//We don't want the TotalWarfareHangarDoorClosed to be less than the total amount of Warfare Hangar Doors in our group so we add 1 if so
			if(TotalWarfareHangarDoorClosed < -TotalWarfareHangarDoor){
				TotalWarfareHangarDoorClosed = TotalWarfareHangarDoorClosed + 1;
			}
		}
		//This section below controls the colour of the lights in the "HangarInteriorLight" Group
		//Check to see if the total amount of Warfare Hangar Door Closed matches the total amount of Warfare Hangar Doors in the Group
		if(TotalWarfareHangarDoor == TotalWarfareHangarDoorClosed) {
			//If all Warfare Hangar Door doors are Closed, change all Interior Lights in the "HangarInteriorLight" Group to Green
			foreach(var HangarInteriorLightblock in HangarInteriorLight) {
				HangarInteriorLightblock.SetValue<Color>("Color", Color.Green);
			}
		}
		else {
			//If any Warfare Hangar Door doors are Open, Opening or Closing, change all Interior Lights in the "HangarInteriorLight" Group to Red
			foreach(var HangarInteriorLightblock in HangarInteriorLight) {
				HangarInteriorLightblock.SetValue<Color>("Color", Color.Red);
			}
		}
	}
	//Print the Total Warfare Hangar Doors Closed to the Debug Panel
	Echo ("Total Warfare Hangar Doors Closed" + TotalWarfareHangarDoorClosed);
}