Skip to content

Instantly share code, notes, and snippets.

@Fank
Last active January 13, 2017 18:20
Show Gist options
  • Save Fank/dc47dc39bab756190fa806dc01d01382 to your computer and use it in GitHub Desktop.
Save Fank/dc47dc39bab756190fa806dc01d01382 to your computer and use it in GitHub Desktop.
Space Engineers Sluice Management with 2 doors, 2 lights, 1 Airvent and 1 Timer
public Program() {
// The constructor, called only once every session and
// always before any other method is called. Use it to
// initialize your script.
//
// The constructor is optional and can be removed if not
// needed.
}
public void Save() {
// Called when the program needs to save its state. Use
// this method to save your state to the Storage field
// or some other means.
//
// This method is optional and can be removed if not
// needed.
}
public void Main(string argument) {
// The main entry point of the script, invoked every time
// one of the programmable block's Run actions are invoked.
//
// The method itself is required, but the argument above
// can be removed if not needed.
// Read some persisted data from Storage
Echo("Argument from last time was " + Storage);
if (argument == "" && Storage != "") {
argument = Storage;
}
else if (argument == "" && Storage == "") {
return;
}
else {
Storage = argument;
}
var arguments = argument.Split('-'); // For example "Sluice1-Open-Internal"
IMyDoor door = GridTerminalSystem.GetBlockWithName(arguments[0] + " Door " + arguments[2]) as IMyDoor;
IMyAirVent airVent = GridTerminalSystem.GetBlockWithName(arguments[0] + " Air Vent") as IMyAirVent;
IMyTimerBlock timer = GridTerminalSystem.GetBlockWithName(arguments[0] + " Timer") as IMyTimerBlock;
IMyLightingBlock light1 = GridTerminalSystem.GetBlockWithName(arguments[0] + " Light 1") as IMyLightingBlock;
IMyLightingBlock light2 = GridTerminalSystem.GetBlockWithName(arguments[0] + " Light 2") as IMyLightingBlock;
switch (arguments[1]) {
case "Open":
switch (arguments[2]) {
case "Internal":
if (airVent.GetOxygenLevel() == 0 && airVent.CanPressurize) {
light1.ApplyAction("OnOff_On");
light2.ApplyAction("OnOff_On");
airVent.ApplyAction("Depressurize_Off");
timer.ApplyAction("Start");
}
else if (airVent.GetOxygenLevel() == 1) {
timer.ApplyAction("Stop");
light1.ApplyAction("OnOff_Off");
light2.ApplyAction("OnOff_Off");
door.ApplyAction("Open_On");
Storage = "";
}
else {
timer.ApplyAction("Start");
}
break;
case "External":
if (airVent.GetOxygenLevel() == 1 && !airVent.IsDepressurizing) {
light1.ApplyAction("OnOff_On");
light2.ApplyAction("OnOff_On");
airVent.ApplyAction("Depressurize_On");
timer.ApplyAction("Start");
}
else if (airVent.GetOxygenLevel() == 0) {
timer.ApplyAction("Stop");
light1.ApplyAction("OnOff_Off");
light2.ApplyAction("OnOff_Off");
door.ApplyAction("Open_On");
Storage = "";
}
else {
timer.ApplyAction("Start");
}
break;
}
break;
case "Close":
Storage = "";
switch (arguments[2]) {
case "Internal":
door.ApplyAction("Open_Off");
break;
case "External":
door.ApplyAction("Open_Off");
break;
}
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment