private void PistonControl(string switchName, string displayNum, string pistonName, string action) { IMyButtonPanel panel = (IMyButtonPanel)GridTerminalSystem.GetBlockWithName(switchName); IMyTextSurface surface = ((IMyTextSurfaceProvider)panel).GetSurface(Int32.Parse(displayNum)); IMyPistonBase piston = (IMyPistonBase)GridTerminalSystem.GetBlockWithName(pistonName); if (action == "On/Off") { bool pistonEnabled = piston.Enabled; if (pistonEnabled) { surface.BackgroundColor = Color.Red; } else { surface.BackgroundColor = Color.Green; } piston.Enabled = !pistonEnabled; } if (action == "Reverse") { piston.Reverse(); if (piston.Velocity < 0) { surface.BackgroundColor = Color.Red; } else { surface.BackgroundColor = Color.Green; } } }
public void retractPistons(List <IMyTerminalBlock> pistonList) { if (getActualPistonExtend(pistonList, false) == getMaxPistonExtend(pistonList, false) && !finishedMining) { } { finishedMining = true; for (int i = 0; i < pistonList.Count; i++) { IMyPistonBase pistonList_X = GridTerminalSystem.GetBlockWithName(pistonList[i].CustomName) as IMyPistonBase; if (pistonList_X.CustomName.Contains(pistonNameTag) && !pistonList_X.CustomName.Contains("Extender")) { pistonList_X.Reverse(); } } } }
public void Main(string argument, UpdateType updateSource) { try { switch (argument) { case "RUN": { if (!running) { switch (_state) { case State.Closed: { _pistonInOut.Reverse(); _timer.TriggerDelay = 0.5f; _timer.StartCountdown(); _gear.Unlock(); _state = State.Open_Initial; running = true; } break; case State.Open: { _pistonSlide.Reverse(); _timer.TriggerDelay = 5f; _timer.StartCountdown(); _state = State.Close_Initial; running = true; } break; } } } break; case "TIMER": { if (running) { switch (_state) { case State.Open_Initial: { _pistonSlide.Reverse(); _timer.TriggerDelay = 5f; _timer.StartCountdown(); _state = State.Open_Final; } break; case State.Open_Final: { _state = State.Open; running = false; } break; case State.Close_Initial: { _pistonInOut.Reverse(); _timer.TriggerDelay = 0.5f; _timer.StartCountdown(); _state = State.Close_Final; } break; case State.Close_Final: { _gear.Lock(); _state = State.Closed; running = false; } break; } } } break; } } catch (Exception e) { EchoText("Error: " + e.Message); } }