Space Engineers

Space Engineers

XPAR Mimir (OBSOLETE)
Acest topic a fost închis
Craig P  [dezvoltator] 16 iul. 2015 la 15:58
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; ...
Editat ultima dată de Craig P; 16 iul. 2015 la 16:13
< >
Se afișează 1-2 din 2 comentarii
Craig P  [dezvoltator] 16 iul. 2015 la 16:10 
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"); }
Editat ultima dată de Craig P; 16 iul. 2015 la 16:15
Craig P  [dezvoltator] 12 sept. 2015 la 6:42 
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. } } }
Editat ultima dată de Craig P; 12 sept. 2015 la 6:45
< >
Se afișează 1-2 din 2 comentarii
Per pagină: 1530 50