I would like to execute a series of events at the time at which they occur.The events are stored in a list and always sorted by time of execution.volatileEvents.Sort(SortScriptEventAscending.Comparer);I would like to have my update method execute the following points.The list should be checked to see if it contains any events (if not then don't continue)The events should be executed and remain in the list until the next event is executedOnce the current event is executed the previous event should be removedEvents should always be checked to see if they have either expired or are yet to occurI have the basic conditions implemented but the algorithm doesn't work as intended.        float currentTime = game.ScriptTimer.CurrentTime;        int numEvents = volatileEvents.Count;        // Check for no events        if (numEvents == 0)        {            return;        }        // Check for expired events        while (volatileEvents[0].Time < currentTime)        {            volatileEvents.RemoveAt(0);        }        // Check if the current event has yet to occur         if (volatileEvents[0].Time > currentTime)        {            return;        }        // Protect against index range error        int next = numEvents == 1 ? 0 : 1;        ScriptEvent currentEvent = volatileEvents[0];        ScriptEvent nextEvent = volatileEvents[next];        // Update the current value based on the script and event parameters         float value = currentEvent.Interpolate ?            MathTools.Lerp2D(currentEvent.Value, nextEvent.Value, currentEvent.Time, currentTime, nextEvent.Time) :            currentEvent.Value;I would like some help to achieve the four bullet points as the basic conditions are there but the method's order of execution is incorrect.
Timed series of events. Logic for organizing events based on time?
c#;algorithm;timer
My simplified answer (without interpolation or looping):        int numEvents = events.Count;        // Check if there are any events to execute        if (eventIndex == numEvents)        {            return;        }        // Check if the current event has yet to occur         if (events[eventIndex].Time > currentTime)        {            return;        }        else        {            // Update the property based on the current event            UpdateProperty(events[eventIndex].Value);            // Current event has been executed so increase the event index            eventIndex++;        }