Skip to content

Instantly share code, notes, and snippets.

@seronis
Last active May 13, 2019 23:18
Show Gist options
  • Save seronis/9270a2d23b93e37f000db6534563d6d1 to your computer and use it in GitHub Desktop.
Save seronis/9270a2d23b93e37f000db6534563d6d1 to your computer and use it in GitHub Desktop.
Space Engineers Scripting Tutorial Scenario - Updated Code for 3rd Tut
// This program is there to try to open the inside door to do so
// it will check if the oxygen level in the sas is at the same
// level as in the room in which case it will open the door
// otherwise it will trigger the timer to pressurize the sas and
// start the timer to check again until it can open the door.
public bool TryOpenInDoor()
{
var outDoor = GridTerminalSystem.GetBlockWithName("SasOutDoor") as IMyDoor;
var inDoor = GridTerminalSystem.GetBlockWithName("SasInDoor") as IMyDoor;
var sasAirVent = GridTerminalSystem.GetBlockWithName("SasAirVent") as IMyAirVent;
var roomAirVent = GridTerminalSystem.GetBlockWithName("SasProgramRoomAirVent") as IMyAirVent;
if (inDoor.Enabled == false)
{
return false;
}
else if (outDoor.Status == DoorStatus.Open)
{
return false;
}
else if (sasAirVent.GetOxygenLevel() != roomAirVent.GetOxygenLevel())
{
return false;
}
inDoor.OpenDoor();
return true;
}
public void Main()
{
if (TryOpenInDoor() == false)
{
var myPreTimer = GridTerminalSystem.GetBlockWithName("SasPressurizeTimer") as IMyTimerBlock;
var myDepTimer = GridTerminalSystem.GetBlockWithName("SasDepressurizeTimer") as IMyTimerBlock;
if (myPreTimer != null
&& myDepTimer != null
&& myPreTimer.IsCountingDown == false
&& myDepTimer.IsCountingDown == false)
{
myPreTimer.ApplyAction("TriggerNow");
}
var OpenInDoorTimer = GridTerminalSystem.GetBlockWithName("SasOpenInTimer") as IMyTimerBlock;
if (OpenInDoorTimer != null && myDepTimer.IsCountingDown == false)
OpenInDoorTimer.ApplyAction("Start");
}
}
// This program is there to try and open the outside door to do
// so it will check if the oxygen level in the sas is at 0% in
// which case it will open the door otherwise it will trigger the
// timer to depressurize the sas and start the timer to check
// again until it can open the door.
//!\ Warning:
// Part of this code is missing take a look at the code from the
// SasInDoorProgram's code and try to fix it!
public bool TryOpenOutDoor()
{
var outDoor = GridTerminalSystem.GetBlockWithName("SasOutDoor") as IMyDoor;
var inDoor = GridTerminalSystem.GetBlockWithName("SasInDoor") as IMyDoor;
var sasAirVent = GridTerminalSystem.GetBlockWithName("SasAirVent") as IMyAirVent;
// We dont need the room's Air Vent this time we just want all the oxygen to be salvaged
if (outDoor.Enabled == false)
{
return false;
}
else if (inDoor.Status == DoorStatus.Open)
{
return false;
}
else if (sasAirVent.GetOxygenLevel() > 0)
{
return false;
}
/* Missing Code */
return true;
}
public void Main()
{
if (TryOpenOutDoor() == false)
{
var myPreTimer = GridTerminalSystem.GetBlockWithName("SasPressurizeTimer") as IMyTimerBlock;
var myDepTimer = GridTerminalSystem.GetBlockWithName("SasDepressurizeTimer") as IMyTimerBlock;
if (myPreTimer != null
&& myDepTimer != null
&& myPreTimer.IsCountingDown == false
&& myDepTimer.IsCountingDown == false)
{
myDepTimer.ApplyAction("TriggerNow");
}
var OpenOutDoorTimer = GridTerminalSystem.GetBlockWithName("SasOpenOutTimer") as IMyTimerBlock;
if (OpenOutDoorTimer != null && myPreTimer.IsCountingDown == false)
OpenOutDoorTimer.ApplyAction("Start");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment