Time Events

Estimated reading time: 2 minutes

The TimeEvents module handles time-related events. It allows registering events that trigger at specific times or intervals (e.g. per second, per minute, hourly, daily, monthly) and on time travel.

Use maplebirch.dynamic.regTimeEvent (the underlying manager is maplebirch.dynamic.Time). For legacy “Simple Frameworks” scripts, the global TimeEvent class still bridges to regTimeEvent (see Getting Started).

Game version & v3.2.5

The framework pins GameVersion to >=0.5.9.7. v3.2.5 includes time-event fixes targeting that line; mirror the same constraint in your mod’s dependenceInfo when you rely on these APIs.

Core API

regTimeEvent(type, eventId, options)

Register a new time event.

  • @param type (string): Event type — onSec, onMin, onHour, onDay, onWeek, onMonth, onYear, onBefore, onThread, onAfter, onTimeTravel
  • @param eventId (string): Unique event identifier
  • @param options (TimeEventOptions): Event configuration
  • @return boolean: Whether registration succeeded
// Register a daily event
maplebirch.dynamic.regTimeEvent("onDay", "dailyCheck", {
  action: (data) => {
    V.dayCounter = (V.dayCounter || 0) + 1;
  },
  cond: (data) => data.currentDate.hour >= 6 && data.currentDate.hour < 18,
  priority: 5,
  once: false,
});

delTimeEvent(type, eventId)

Unregister a time event.

maplebirch.dynamic.delTimeEvent("onDay", "dailyCheck");

timeTravel(options)

Jump game time forward or backward.

// Jump to specific date
maplebirch.dynamic.timeTravel({
  year: 2025,
  month: 3,
  day: 15,
  hour: 12,
});

// Jump forward by duration
maplebirch.dynamic.timeTravel({
  addDays: 7,
  addHours: 6,
});

Event Options

OptionTypeDescription
actionfunctionCalled when triggered, receives TimeData
condfunctionCondition function, returns boolean
prioritynumberHigher runs first
oncebooleanTrigger only once
accumulateobjectAccumulate trigger config
exactbooleanTrigger at exact time boundary