Farming and life game calendars count from day 1, but dividing by 28 counts from 0. In our Godot 4.7 test of 4 seasons of 28 days, day / 28 made Spring 27 days long, called day 28 Summer day 0, and on day 112, the last day of Winter, gave index 4, one past the 4 seasons, and year 2. Subtracting 1 first gave every season 28 days, numbered 1 to 28.
The code
Keep one day counter that starts at 1 and goes up each morning, and save only that. Ask the script for season_index(day), day_of_season(day) and year(day) when you need them.
extends Node
## Season, day of the season and year from a day counter that starts at 1,
## like most farming and life game calendars: 4 seasons of 28 days.
const DAYS_PER_SEASON := 28
const SEASONS := ["Spring", "Summer", "Fall", "Winter"]
static func season_index(day: int) -> int:
return ((day - 1) / DAYS_PER_SEASON) % SEASONS.size()
static func day_of_season(day: int) -> int:
return (day - 1) % DAYS_PER_SEASON + 1
static func year(day: int) -> int:
return (day - 1) / (DAYS_PER_SEASON * SEASONS.size()) + 1
What we measured
Every day of the first year, and the days around season and year ends. Two runs with the same numbers.
day / 28: Spring 27 days, Summer, Fall and Winter 28, and 1 day with index 4. Day 0 of a season shown 4 times a year, on days 28, 56, 84 and 112.- Day 28 came out as Summer day 0 instead of Spring day 28. Day 112 gave index 4, which with % 4 wraps to Spring day 0 of year 2, a day early.
- The script: 28 days in every season, never day 0, day 112 is Winter day 28 of year 1 and day 113 is Spring day 1 of year 2.
Why it happens
Integer division puts 0 to 27 in the first group. A counter that starts at 1 has only 27 of those days in Spring and pushes day 28 into the next group. Doing the math on day - 1 lines the groups up again, and + 1 gives the day back its human number.
What to change
- Other season lengths: change DAYS_PER_SEASON.
- Seasonal effects follow the season index, for example falling leaves while it is 2, Fall.
Effects only at night, even across midnight: night-only effects.
Ready-made cozy effects: Cozy VFX for Godot 4 has 29 ready-made effects for farming and life games, including fireflies, sleeping Zzz, hearts, music notes, steam and falling leaves.
Tested in Godot 4.7 with the Compatibility renderer.
Ready-made: Cozy VFX for Godot 4 has 29 ready-made effects for farming and life games, including fireflies, sleeping Zzz, hearts, music notes, steam and falling leaves.
More how-tos for Cozy VFX for Godot 4: Night-only effects when the night crosses midnight
More how-tos: Game systems
- Hover a 3D object inside a SubViewport
- A turned building that covers the cells it stands on
- An inventory that never loses an item and never overfills a stack
- A JSON save that loads back exactly what you saved
- Fire that spreads one cell per step, in every direction
- A pooled enemy that comes back as fresh as a new one
- An enemy that stops at the dead player and finds the respawned one
- Poison, burn and bleed that keep ticking when applied again
- XP, qi and gold that keep growing without going negative
- Count slot line wins with wilds in front
- Random directions spread evenly over a sphere or a cone
- Count a lap only when the car really went round
- Make a seed repeat: daily runs, replays and roguelike seeds
- Offline progress that counts the time the game was closed
- A chance roll without the long bad-luck streaks
- Check crafting recipes in any order, with the right counts
- Make HP and mana regen the same at any frame rate
- Damage over time with the right number of ticks
- Spawn enemies where the camera cannot see them
- Keep a chasing horde from stacking into one enemy
- Make the fish bite after the same wait at any frame rate
- Snap buildings to the right grid cell on both sides of the origin
- Make a cooking timer fire once, on time
- Pick from a weighted loot table with the right chances
- Level up as many times as the XP covers
- Walk a patrol guard to each point without overshooting
- Remove items from an Array while checking them, without skipping any
- Scatter spikes, roots or trees in a circle without overlaps
- Count and take crafting items from every stack
- Play random sounds and events without obvious repeats
- Pick the growth image so the ripe one shows exactly when the crop can be picked
- An enemy that dies once, however many hits land
- A fair shuffle you can replay
- A ghost that drives the lap at real speed
- A vision cone that does not flicker at the edge
- Move a group of units without a pile-up
- A sprinkler that waters a round patch
- A slot reel that always lands forward on the result
- A crowd of NPCs that never emote or bob in step
- A song position that moves on every frame
- Nodes your editor tool adds that stay in the scene