} // Update method public void Delay(int sec = 0) { if (sec == 0) // Check if there is a defined time { timer.ApplyAction("TriggerNow"); // Run "Trigger Now" on timer } // if sec 0 else { timer.SetValue("TriggerDelay", Convert.ToSingle(sec)); // Set the timer delay timer.ApplyAction("Start"); // Start the timer //timer.ApplyAction("Stop"); } // else sec 0 } // Delay method
private void KickTimer(ZACommons commons) { IMyTimerBlock timer = null; // Name takes priority over group if (TimerName != null) { var blocks = ZACommons.SearchBlocksOfName(commons.Blocks, TimerName, block => block is IMyTimerBlock && ((IMyTimerBlock)block).Enabled); if (blocks.Count > 0) { timer = blocks[0] as IMyTimerBlock; } } if (timer == null && TimerGroup != null) { var group = commons.GetBlockGroupWithName(TimerGroup); if (group != null) { var blocks = ZACommons.GetBlocksOfType <IMyTimerBlock>(group.Blocks, block => block.CubeGrid == commons.Me.CubeGrid && ((IMyTimerBlock)block).Enabled); timer = blocks.Count > 0 ? (IMyTimerBlock)blocks[0] : null; } } if (timer != null) { // Rules are simple. If we have something in the tick queue, trigger now. // Otherwise, set timer delay appropriately (minimum 1 second) and kick. // If you want sub-second accuracy, always use ticks. if (TickQueue.First != null) { timer.ApplyAction("TriggerNow"); } else if (TimeQueue.First != null) { var next = (float)(TimeQueue.First.Value.When.TotalSeconds - TimeSinceStart.TotalSeconds); // Constrain appropriately (not sure if this will be done for us or if it // will just throw). Just do it to be safe. next = Math.Max(next, timer.GetMinimum <float>("TriggerDelay")); next = Math.Min(next, timer.GetMaximum <float>("TriggerDelay")); timer.SetValue <float>("TriggerDelay", next); timer.ApplyAction("Start"); } // NB If both queues are empty, we stop running } }
static void TriggerTimer(IMyTimerBlock timer, float delay) { timer.SetValue("TriggerDelay", delay); timer.GetActionWithName("Start").Apply(timer); }