Space Engineers

Space Engineers

Oxygen Sensor (Works in Vanilla SE - No mods needed)
standing appa 30 Jan, 2018 @ 11:44am
Line 50 Error
Error:
Program(50, 30): Error:"IMyBlockGroup" does not contain a definition for "Blocks" and no
extension method "Blocks" accepting a first argument of type "IMyBlockGroup" could be found
(are you missing a using directiv or an assembly reference?)

Pleas help me. I think this is one the best oxygen scripts ever made and I really want to use it.

----------------------------------------------------------------------------------------------------------
Code:
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 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);
} else {
LCDText += " All " + airVents.Count + " zones are currently pressurised";
}

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>();
GridTerminalSystem.GetBlockGroups(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-1 of 1 comments
Sheogorath 6 Apr, 2019 @ 4:04am 
Don't know if this is still used by people but i fixed it by rewriting the "method for finding block groups" with this:
// Method for finding block groups List<IMyTerminalBlock> GetBlocksFromGroup(string group) { IMyBlockGroup taggedGroup = GridTerminalSystem.GetBlockGroupWithName(group); List<IMyTerminalBlock> listGroup = new List<IMyTerminalBlock>(); List<IMyTerminalBlock> finallist = new List<IMyTerminalBlock>(); if (taggedGroup != null) { taggedGroup.GetBlocks(listGroup); } //check group tagged blocks are of right type for (int i = 0; i < listGroup.Count; i++) { if (listGroup is IMyTextPanel)//Can be made generic
finallist.Add(listGroup);
}
if (finallist != null)
{
return finallist;
}
throw new Exception("GetBlocksFromGroup: Group \"" + group + "\" not found");
}[/code]
Last edited by Sheogorath; 6 Apr, 2019 @ 4:05am
< >
Showing 1-1 of 1 comments
Per page: 1530 50