To fix this you need to change this section so you’ve two variables with different names:
- dayOfWeek - the number represent which day it is
- daysOfWeek - the list of each days name
Right now you assign 6 to daysOfWeek
, then assign a list to it (actually it’s more complicted because of the way default, define, and loaded games work):
default daysOfWeek = 6
define daysOfWeek = [
"Monday", # 0
....
Change to:
default dayOfWeek = 6 # The current day of the week
define daysOfWeek = [ # The names of each day of the week
"Monday", # 0
....
The two new Python functions need to go in the init python
block, and test the right variable dayOfWeek
(the number) rather than daysOfWeek
(the list of strings).
To advance the day count and dayOfWeek
automatically you could modify your tick function to make the changes when time rolls over/past to the first period. This works for the case where the character parties until dawn.
It needs some care though if the character starts an activity late at night as the day might roll over before they choose to sleep. All date/time implementations get a little tricksy if you allow activities where the PC’s sleep cycle gets decoupled from the day/night cycle. This is why I made rolling the day/dayOfWeek optional in my original version. Your life will be simpler if you avoid this happening, but it may be inevitable depending on your scenario (In Tramp the PC’s midnight snacking is one place this occurs: the day has rolled over, but they haven’t finished sleeping yet).
So this whole block becomes (with rolling day/dayOfWeek):
init python:
def tick(amount=1):
global day, dayOfWeek, time, time_map, timestr
time += amount
if time > len(time_map) - 1:
day += time // len(time_map) # Advance day
dayOfWeek += time // len(time_map) # Advance day of week
dayOfWeek %= len(daysOfWeek) # Wrap day of week back to Monday
# dayOfWeekStr = daysOfWeek[dayOfWeek] # update if you are using this
time %= len(time_map)
timestr = time_map[time]
def isWeekday():
return dayOfWeek <= 5
def isWeekend():
return dayOfWeek >= 6
At the end of each activity you just use the appropriate number of ticks, usually one, but could be more. The day and dayOfWeek will change at midnight.
It can be useful when implementing sleep to have a function that goes to the start of the next day. This is the nextDay
function I originally had. Without it you have to work out how many ticks to add to roll the day over.
label sleep:
"You curly up in bed and are soon asleep."
# $ tick(len(time_map) - time) # You have to do this without the nextDay function
$ nextDay()
# Reset player energy if you are tracking that
"Your alarm is going off before you know it. It's a fresh new day."
jump main
For after those all-night parties you may want this instead:
label daytimeSleep:
"You really need some sleep, so you flop into bed exhausted."
$ tick(2) # Maybe 3?
# Reset player energy if you are tracking that, possibly not the full amount?
"You wake up later the same day."
jump main
This might be the result of an un-closed “{size=-2}” text tag or similar thing that modifies the text size.