Verse Library verse

01 Snippet

Schedules live events with recurring timestamps using simulation sleep, handling past dates and suspending until trigger time.

extracted-snippets/community/snippets/33E7/fortnite-live-event-scheduler/01-snippet.verse

# Source URL: https://dev.epicgames.com/community/snippets/33E7/fortnite-live-event-scheduler
# Local doc:  epic-docs/community/snippets/33E7/fortnite-live-event-scheduler.md
  using { /Verse.org/SceneGraph }
  using { /Verse.org/Simulation }
  using { /Fortnite.com/Devices }
  # Strategy interface for event scheduling
  schedule_strategy<public> := interface<castable>(p_interface):
  ScheduleEvent<public>(Event:live_event)<suspends>:void
  <#
  Sleep strategy: Sleeps until event time
  Note: Sleep() uses simulation time, so server lag can cause delays
  #>
  sleep_schedule_strategy<public> := class<concrete>(schedule_strategy):
  ScheduleEvent<override>(Event:live_event)<suspends>:void=
  # If recurring event timestamp is in the past, jump to next future occurrence
  if (RecurInterval := Event.RecurEvery?):
  CurrentTime := GetSecondsSinceEpoch()
  if (Event.Timestamp < CurrentTime):
  TimeSinceStart := CurrentTime - Event.Timestamp
  PeriodsToAdd := Ceil[TimeSinceStart / RecurInterval] or 1
  set Event.Timestamp = Event.Timestamp + (PeriodsToAdd * RecurInterval)
  loop:
  CurrentTime := GetSecondsSinceEpoch()
  TimeUntilEvent := Event.Timestamp - CurrentTime
  if (TimeUntilEvent <= 0.0):
  spawn. Event.RunEvent()
  # Schedule next occurrence
  if (RecurInterval := Event.RecurEvery?):
  TimeSinceTrigger := CurrentTime - Event.Timestamp
  PeriodsToAdd := Max(1, Ceil[TimeSinceTrigger / RecurInterval]) or 1

Sign in free to read the full source 🌴

This Verse Library file is members-only. Create a free account to view the complete source and download the .verse file.

Sign in with Discord

Comments

    Sign in to vote, comment, or suggest an edit. Sign in