How to make a time and energy system

So i wanna make a day system, not a complex one just one that has like 5 stages (Dawn, Morning, Afternoon, Dusk, Night) that when it progresses decreases your energy. For example…

A person has a number called Energy.
The Energy of yourself is 100.
The Energy of a person is usually 100.

and every time a time of day passes you lose like 15 Energy so you wake up at Dawn and by night you’ve lost 60 Energy (other things would lose you energy as well) and then you can sleep in a bed to recover all your energy. Which is another thing i’m unsure of how to do yet though i haven’t googled if anyone has a way to do that yet i’m going to do that after this.

but my question is how would i set this up so it works, i’ve tried to work with the built in time system but i’ve never figured it out and would love some help or advice from more knowledgable devs and creators.

1 Like

There are many methods, but I can speak in general about how I do things.

Set up a variable that represents the time of day. I usually decide 0=dawn, 1=morning, etc. I am rusty with Inform, but you might also be able to use a “value that varies” with named units but sometimes for code purposes it’s good to have it as an integer to check.

Then you’ll want to create a phrase with a routine that “ticks the clock” and can be set off wherever you need it - either manually with story progression, or by counting turns - however you want to do it.

Assuming your variable is called “phase”. (This is pseudocode which you will need to tweak - again, rusty!)

to tick the clock:
    increase phase by 1;
    if phase is greater than 4:
        set phase to 0;
    decrease energy by 15;
    [other things that happen, mana regeneration, messages about sun rising or setting, whatever]

Then you can use that as a command:

Carry out going north in endless desert:
    tick the clock.
After talking to the StoryTeller:
    say "'I'm going to tell you a very long story,' says the StoryTeller. Once upon a time...'";
    tick the clock;
    say "'...and they all lived happily ever after!' finally concludes the StoryTeller, looking like he might need a smoke break."


Every turn when the player is on comfy bed:
    say "You snooze peacefully and are rejuvenated!";
    tick the clock;
    increase energy by 30.


Before entering the Useful Shoppe:
    if phase is less than 1 or phase is greater than 3:
        say "The Useful Shoppe is unfortunately closed right now, come back during business hours." instead.
Check taking heavy anvil:
    if energy is less than 20:
        say "You don't have the energy to pick up the anvil right now." instead;

Carry out taking heavy anvil:
       decrease energy by 5:
       say "Urrghphhh! Heavy! (Your energy decreases by 5...)"
1 Like

Is your goal to advance time when things happen in the story, like in Anchorhead or Vespers, or to have it advance every time the player types a command, like in Suspended or Deadline?

1 Like

i’ll play around with this and see what i can figure out.

1 Like

i want the time to kinda work like informs built in clock, every move moves time forward and you can set actions to not move time. I just don’t understand how the built in clock works and figured someone here may be able to help set it up and inform me on at least where to look for the commands and phrases to use it.

The Recipe Book §4.1: The Passage of Time has examples covering the basics. You may also be interested in Variable Time Control by Eric Eve.

1 Like

Every Turn Rules
The Time of Day
Telling the Time
(You can also go forward from there for some more useful documentation about measuring time.)

There’s a “clock” built into inform that by default starts at 9:00 AM and ticks a minute on every in-world turn. Since you’re using phases, you may want to ignore that and just run an every turn rule…for example if you want a phase of the day to take 20 turns, increment a variable every turn, and when that reaches 20 run your clock tick/movement mechanism and reset the turn variable.


You can also tap into the existing time-of-day system with scenes.

Dusk is a recurring scene.
Dusk begins when the time of day is 7:00 pm.
Dusk ends when the time of day is 9:00 pm.

When dusk begins...
When dusk ends...
Every turn when dusk is happening...
Instead of sleeping when dusk is happening...

Variable time clock has an issue with Inform 10.1.2, namely that, at least in the example, the time increase in the form [x secs] is doubled (x codex increase the time by 4 minutes (240 secs) instead of 2 minutes (120 secs).

I suspect that something is called twice, but is a quick serendipidity test (I have done it this morning, in investigating the Linux IDE & CLI issues with extensions; now there’s 187 extensions installed in ~/Inform without IDE issues)

Best regards from Italy,
dott. Piergiorgio.

1 Like

Yes, it’s deliberate that it’s not in the Friends 10.1 repo yet, but I don’t know what version @FalseRevenant is on and I figured it’s still worth mining for ideas.

1 Like

I don’t know how to use Inform 7, but I’m posting here to wish you luck. Time of day and energy implementations for turn-based stuff can quickly become a really large can of worms, depending on how thorough you plan to be.

1 Like