SpaceEngineers scripting tips and snippets
Tips and Snippets.
Space Engineers uses C# with custom namespaces.
API wiki at spaceengineerswiki
Good repository with tutorials at MDK-SE
public Program()
{
Runtime.UpdateFrequency = UpdateFrequency.Update100;
}
public void Save()
{
}
public void Main(string argument, UpdateType updateSource)
{
}
var lcd = GridTerminalSystem.GetBlockWithName("LCD") as IMyTextPanel;
List<IMyTerminalBlock> lcds = new List<IMyTerminalBlock>();
GridTerminalSystem.SearchBlocksOfName("LCD", lcds);
List<IMyTerminalBlock> batteries = new List<IMyTerminalBlock>();
GridTerminalSystem.GetBlocksOfType<IMyBatteryBlock>(batteries);
IMyBlockGroup group = GridTerminalSystem.GetBlockGroupWithName("Ship Batteries");
List<IMyTerminalBlock> blocks = new List<IMyTerminalBlock>();
group.GetBlocks(blocks);
foreach (var block in blocks)
{
Echo(block.CustomName);
}
string getDetailedInfoValue(IMyTerminalBlock block, string name)
{
string value = "";
string[] lines = block.DetailedInfo.Split(new string[] { "\r\n", "\n", "\r" }, StringSplitOptions.None);
for (int i = 0; i < lines.Length; i++)
{
string[] line = lines[i].Split(':');
if (line[0].Equals(name))
{
value = line[1].Substring(1);
break;
}
}
return value;
}
int getPowerAsInt(string text)
{
if (String.IsNullOrWhiteSpace(text))
{
return 0;
}
string[] values = text.Split(' ');
if (values[1].Equals("kW"))
{
return (int) (float.Parse(values[0])*1000f);
}
else if (values[1].Equals("kWh"))
{
return (int) (float.Parse(values[0])*1000f);
}
else if (values[1].Equals("MW"))
{
return (int) (float.Parse(values[0])*1000000f);
}
else if (values[1].Equals("MWh"))
{
return (int) (float.Parse(values[0])*1000000f);
}
else
{
return (int) float.Parse(values[0]);
}
return 0;
}