Space Engineers

Space Engineers

XPAR Mimir (OBSOLETE)
This topic has been locked
Craig P  [developer] Jul 16, 2015 @ 3:58pm
Code Snippets
Here is where I'll post helpful code snippets! Feel free to post your own, after verifying that they definitely work. Always use the most up-to-date version of Mimir!

Please do not post chatter to this discussion. I'm happy to talk, but do it in another discussion, because this one should be just a rain of code snippets.

A snippet for if you want your fighter to automatically lock/unlock landing gear based on connections (useful if you have mechanical landing gear). Please note that it doesn't intefere with other uses of landing gear, because it only fires when the state of the connector changes.

void CustomLogic() { if (CheckHigh("Connector")) Apply("*Gear.Lock"); else if (CheckLow("Connector")) Apply("*Gear.Unlock"); ...

If you want your fighter to stop executing Mimir code (because it's interfering with the station systems), try this:

void CustomLogic() { if (IsHigh("Connector")) return; ...
Last edited by Craig P; Jul 16, 2015 @ 4:13pm
< >
Showing 1-2 of 2 comments
Craig P  [developer] Jul 16, 2015 @ 4:10pm 
Due to the recent update, most of my old AIs don't work any more. Mimir still does.

If you want Freya-like functionality, here are some tips:

void CustomLogic() { // Turn reactors off when your panels work, on when they don't. if (CheckHigh("Solar Panel")) Apply("*Reactor.Off"); if (CheckLow("Solar Panel")) Apply("*Reactor.On"); // Use batteries until they get low, then recharge them. if (CheckHigh("Battery", 0.8)) Apply("*Battery.Discharge;*Reactor.Off"); if (CheckLow("Battery", 0.2)) Apply("*Battery.Charge;*Reactor.On"); // Activate batteries if reactors are maxed. if (Output("Main Reactor") > 0.8) Apply("*Battery.Discharge"); if (Output("Main Reactor") < 0.2) Apply("*Battery.Charge"); }
Last edited by Craig P; Jul 16, 2015 @ 4:15pm
Craig P  [developer] Sep 12, 2015 @ 6:42am 
Here's mode advanced battery management. Remember to change the names if your blocks have other names! If you need faster action from this, you can also change canRunFast.

This is not thoroughly tested.

// List of batteries List<IMyTerminalBlock> batteries = new List<IMyTerminalBlock>(); void CustomLogic() { // Fetch the list, if needed. Do not do this every time, it creates a memory leak if (batteries.Count == 0) GridTerminalSystem.GetBlocksOfType<IMyBatteryBlock>(batteries); // Check power consumption. This will be 0 if the solar panels and batteries are doing // their job. double reactorOutput = Output("Reactor"); // Charge low batteries if reactor is low,discharge full batteries if reactor is working hard. for (int a = 0; a < batteries.Count; a++) { double charge = Status(batteries[a]); if ( (reactorOutput > 0.3) && (charge > 0.8) ) ApplyToBlock(batteries[a], "Discharge"); if ( (reactorOutput < 0.7) && (charge < 0.5) ) { ApplyToBlock(batteries[a], "Charge"); break; // we cannot risk switching a lot of batteries into charge mode, so only one per call. } } }
Last edited by Craig P; Sep 12, 2015 @ 6:45am
< >
Showing 1-2 of 2 comments
Per page: 1530 50