Space Engineers

Space Engineers

Oxygen Sensor (Works in Vanilla SE - No mods needed)
acheaen 1 Apr, 2015 @ 3:20pm
problem with IMyDoor
so i was playing with your mod trying to make an emergency system in you script. i was able to make 4 red lights flash in sync with the alarm when pressure was lost. i added your door part but i keep getting an error on line 38 can u check what i have done maybe you can see what i have missed.

void Main() {
// Define the variables
var LCD = GetBlocksFromGroup("Oxygen LCD Panels");
var airVents = SearchBlocksByName("Air Vent");
var timer = GridTerminalSystem.GetBlockWithName("Timer Block Oxygen") as IMyTimerBlock;
var alarm = GridTerminalSystem.GetBlockWithName("Oxygen Alarm") as IMyFunctionalBlock;
var alarma = GridTerminalSystem.GetBlockWithName("Emergency Lights") as IMyInteriorLight;
var alarmb = GridTerminalSystem.GetBlockWithName("Emergency Lights 2") as IMyInteriorLight;
var alarmc = GridTerminalSystem.GetBlockWithName("Emergency Lights 3") as IMyInteriorLight;
var alarmd = GridTerminalSystem.GetBlockWithName("Emergency Lights 4") as IMyInteriorLight;
var pressureStatus = "Pressurized";
string LCDText = " Life Support System:\r\n\r\n";
var LCDColour = Color.White;

// Check the air vents
for (int i = 0; i < airVents.Count; i++) {
string pressureInfo = airVents.DetailedInfo;
if(pressureInfo.IndexOf("Not pressurized") != -1) {
if(pressureStatus == "Pressurized"){
LCDText += "----------- ALERT ----------- \r\n\r\n";
}
LCDText += airVents.CustomName.Substring(8) + " depressurised \r\n";
LCDColour = Color.Red;
pressureStatus = "Depressurized";
}
}

if(pressureStatus == "Depressurized") {
alarm.GetActionWithName("PlaySound").Apply(alarm);
alarma.GetActionWithName("OnOff_On").Apply(alarma);
alarmb.GetActionWithName("OnOff_On").Apply(alarmb);
alarmc.GetActionWithName("OnOff_On").Apply(alarmc);
alarmd.GetActionWithName("OnOff_On").Apply(alarmd);
// Close all doors when pressure is lost
List<IMyTerminalBlock> allDoors = new List<IMyTerminalBlock>();
GridTerminalSystem.GetBlocksOfType<IMyDoor>(allDoors);
for (int i = 0; i < allDoors.Count; i++) {
allDoors.GetActionWithName("Open_Off").Apply(allDoors);
}
} else {
LCDText += " All " + airVents.Count + "zones are currently pressurised";
alarma.GetActionWithName("OnOff_Off").Apply(alarma);
alarmb.GetActionWithName("OnOff_Off").Apply(alarmb);
alarmc.GetActionWithName("OnOff_Off").Apply(alarmc);
alarmd.GetActionWithName("OnOff_Off").Apply(alarmd);
}

SetText(LCD, LCDText, LCDColour);

// Restart the event handler
timer.GetActionWithName("Start").Apply(timer);

}

// Method for finding blocks by names
List<IMyTerminalBlock> SearchBlocksByName(string blockName) {
var blocks = new List<IMyTerminalBlock>();
GridTerminalSystem.SearchBlocksOfName(blockName, blocks);
return blocks;
}

// Method for finding block groups
List<IMyTerminalBlock> GetBlocksFromGroup(string group) {
var blockGroups = new List<IMyBlockGroup>();
blockGroups = GridTerminalSystem.BlockGroups;
for (int i = 0; i < blockGroups.Count; i++) {
if (blockGroups.Name == group) {
return blockGroups.Blocks;
}
}
throw new Exception("GetBlocksFromGroup: Group \"" + group + "\" not found");
}

// Method for writting to LCD Panels
void SetText(List<IMyTerminalBlock> blocks, string LCDText, Color color) {
for(int i = 0; i < blocks.Count; i++) {
IMyTextPanel panel = blocks as IMyTextPanel;
panel.WritePublicText(LCDText);
panel.SetValue("FontColor", color);
panel.ShowTextureOnScreen();
panel.ShowPublicTextOnScreen();
}
}
< >
Showing 1-2 of 2 comments
acheaen 1 Apr, 2015 @ 3:26pm 
the error i get is as follows

Line 38 :
'System.Collections.Generic.List<Sandbox.ModAPI.Ingame.
IMyTerminalBlock>' does not contain a definition for
'GetActionWithName' and no extension method
'GetActionWithName' accepting a first argument of type
'System.Collections.Generic.List<Sandbox.ModAPI.Ingame.
IMyTerminalBlock>' could be found ,are you missing a
using directive or an assembly reference?
Kesuke  [developer] 6 Apr, 2015 @ 7:09am 
A tiny part of your code is missing; On line 38 change this;

allDoors.GetActionWithName("Open_Off").Apply(allDoors);

to this;

allDoors[i].GetActionWithName("Open_Off").Apply(allDoors[i]);

You need the [i] part. That code is contained in something called a for loop[msdn.microsoft.com], essentially it means "for" each item in a list go through one at a time (until the list is completed) executing some code (in this case the code to close all the doors). That [i] is a reference to which item in the list we want to execute code on. Each time the loop runs it adds 1 to the value of i, so it increments through the list onto the next item. So for example this;

allDoors[1].GetActionWithName("Open_Off").Apply(allDoors[1]);

In this example I have used 1 instead of i. This would execute that code against the second item in the list (because just to add confusion technically 0 is the first item in a list, 1 is second, 2 is third and so on). If you put 2 you would close the third door in the list and so on.

I hope this explains it!
Last edited by Kesuke; 6 Apr, 2015 @ 7:15am
< >
Showing 1-2 of 2 comments
Per page: 1530 50