Skip to content

Run something every month or year

Something happens on a rhythm of the calendar: a harvest each year, a tithe each month, a tale at the turn of a season.

Add an On Date node. It has no input, and the calendar starts it while the scheme runs. Set When to A New Month, A New Season or A New Year, narrow it with Only Month (from 1) or Only Season, and link Began.

  1. In Behaviour ▸ Decisions, click From a template and pick A yearly event for everyone, or A recurring event for a decision that starts its own scheme with a dialogue.
  2. The yearly template’s Action is Only tell the game: nothing happens in the story until your code listens to IM.onDecisionMade, or until you set Action to Start a scheme, Send a signal or Call a method.
  3. Each character no player plays thinks about it on its own rhythm: Think about it every (days) at 360, which matches A year has (days) at first, with Starts at 100. It does not wait for the first day of a year. For that, use On Date or the clock events.
  4. Turn on Characters think for themselves in Behaviour ▸ Settings, as in Let characters start schemes on their own.

Each listener runs in its own try and catch.

Event Gives When
WorldClock.MonthBegan, IM.onMonthBegan Month number, from 1 A month begins. Only with a calendar.
WorldClock.YearBegan, IM.onYearBegan Year number A year begins. Also without a calendar.
WorldClock.SeasonChanged, IM.onSeasonChanged Season ID The season changes. Only with a calendar.
WorldClock.DayPassed, IM.onDayPassed Day number A day has passed.

The demo subscribes in DemoRules.cs, lines 196 and 197, and unsubscribes in OnDisable:

WorldClock.MonthBegan += OnMonth;
WorldClock.YearBegan += OnYear;

Its OnYear starts with if (!Hosting) return;, so only the host of the demo world does the yearly work.

On the day a year begins, the events come in a fixed order: year, month, season, then the day itself. They come once for each day that really passed.

  • Nothing fires. The days do not pass. Days pass is When the game says so at first.
  • A month or season event never comes. The world has no calendar. A year event still comes.
  • A load or a restart raises nothing. The events are not raised when the day is set from code, on a load or on a restart. Use On Game Loaded for that, or WorldClock.Restarted for a load, a restart or a set day.
  • Handlers add up. A static handler you never remove outlives your object. Unsubscribe in OnDisable.
  • Clients. Clients hear the clock events too, as the host’s days arrive, which is why the demo’s handler checks Hosting. WorldClock.Advance does nothing where the game’s mind does not run, such as a multiplayer client, so write to the world from the host only, as the demo does.