Ok so i thought i would add some explanation to @dingotush code that may be helpful. Starting with python and by extension renpy script syntax is mostly white space dependent, and indentation means everything!
define in the renpy script tells the renpy game engine to crate a variable(since its a python engine your really just making a python variable). Python variables are sort of polymorphic, but for the sake of keeping things simple, daysofWeek would be a list and dayOfWeek would be an integer to start.
Ok so i feel like next in the script @dingotush sort of jumped right into the deep end (although its probably the correct way of doing it) @dingotush uses init python: which in renpy script tells the renpy engine that the following indented block is pure python code(note that everything in a python code bock is treated as one line in the renpy script). He then in python inside the code block defines some python functions with default variable inputs(again a slightly advanced move using default variable imputs for a beginner at python).
Ok last thing thing happening back in renpy script outside the init python: is defining a screen in renpy script. using screen yourscreennaemhere(): tells the script the next script block is all for that screen. You can pass variables to the screen inside the () like in a function. and like a function a screen can return something. Getting more advanced a screen is a python class predefined by the renpy engine, and what your actually mainly defining other than the name in the renpy script is the render function of the screen class object. Why this is important to know is renpy pre renders screens. No literally the engine will actually call the render function ahead of time for your screen that way when its time to show that screen it will be done rendering. If you change the value of a variable in the script block for the screen it changes whenever the render function is called, which can be before its displayed to the player. In other words adding a line $ day += 1 to the simpleDateTime screen would make it add 1 to day every time it prerendered or rerendered the screen making your day counter count way to many times and posibly mess with other uses of that variable the player may be interacting with(try addin the above to the screen in his demo code and try it out to see what i mean). If you want a screen to modify variables in your game for instance a button to click to increase a stat you have to do this via screen actions.
So in the script.rpy, again in renpy script were again using define to define another python variable, this time one of renpys custom predefined python classes, a Character which is very useful for making writing in the script easier. Then we define a renpy script label. ( Python does not natively have labels, and uses a library to implement them in python, to be able to use them in the script, i forgot which library its using). Labels in renpy script is just a way of breaking your script up into chunks that you could then call, or jump to. The operate much like a function with some extended abilities, and can have passed variables and return things just like python functions also you dont have to return at the end of a label you can just flow into what ever follows it in the file. Then we proceed to use these newly defined variables and functions to track time, with the day ,dayOfWeek, and period variables which are just integers manipulated by the functions. Hes doing this by using the $ which in renpy script denotes a single line of python code to run. Here we are just calling the functions defined in the other file.
All together were using an integer to track the various time variables because when we put the integer into the key input of a list such as daysOfWeek[yourkeyhere] we can get back the text of what the time period or day it is. We use functions to change our interger variables to make sure we don’t miss manage the time variables, such as going past days end the periods variable accidentally because we forgot to manually check if we matched or exceeded it.
So just for example i modified @dingotush work to show as pure renpy script example as you can get, using script labels instead of python functions. Also being lazy i mashed it into one file:
define daysOfWeek = [
"Monday", # 0
"Tuesday", # 1
"Wednesday", # 2
"Thusday", # 3
"Friday", # 4
"Saturday", # 5
"Sunday", # 6
]
define periodsOfDay = [
"Morning", # 0
"Lunchtime", # 1
"Afternoon", # 2
"Evening", # 3
"Night", # 4
]
default day = 1 # Day number
default dayOfWeek = 0 # Day of week
default period = 0 # Period of day
default dayOfWeekStr = daysOfWeek[dayOfWeek] # Current day of week string
default periodStr = periodsOfDay[period] # Current period string
label addPeriod(delta = 1, rollDay=True):
$ periods = len(periodsOfDay)
$ period += delta
if rollDay:
$ day += period // periods
$ dayOfWeek += period // periods
$ period %= periods
$ dayOfWeek %= len(daysOfWeek)
$ dayOfWeekStr = daysOfWeek[dayOfWeek]
else:
if period >= periods:
$ period = periods - 1
elif period < 0:
$ period = 0
$ periodStr = periodsOfDay[period]
return
label nextDay(delta = 1):
$ period = 0
$ day += delta
$ dayOfWeek += delta
$ dayOfWeek %= len(daysOfWeek)
$ dayOfWeekStr = daysOfWeek[dayOfWeek]
$ periodStr = periodsOfDay[period]
return
screen simpleDateTime():
frame:
xalign 1.0
yalign 0.0
text "Day [day] [dayOfWeekStr:.3s] [periodStr]"
define pc = Character("You")
label start:
show screen simpleDateTime
pc "Urrgh, Mondays. Who needs them?"
"You stay in bed, feeling ill."
call addPeriod()
"You manage to eat a little chicken soup, take an aspirin, and go back to bed."
call addPeriod(2)
"You wake and check your socials, but it is all too much, and you let sleep take you again."
call addPeriod(3)
"Wait ... It's lunchtime? How long did I sleep?"
"No ... this can't be happening. Am I having a lucid dream?"
call addPeriod(-6)
"Your alarm goes off, time to get ready for work."
"End."
return
If you looked at my Project Bob you can see a similar but different setup working. You can open the scripts.rpa in a text editor and search for these variables.
game_days -----> main day tracking integer
day_step ------> same as @dingotush period integer
next_day_step ------> really its an integer that is 1 greater than day_step
day_periods -------> list of day periods
p_navigation is the screen that displays the current day at the start of the day, also has the button for starting the day jumping us to the first label. search for the label start_day to follow the main game loop. for every period of the day we jump to label travel where we go to the location of the action taken and incerment the day_step, then go to the label for that action, at the end of the acition we jump back to travel, if the day_step has reached 6 the end of day we jump to p_day_end to end the day and go back to label main and bring back all the navigation. note that main is a never ending loop bring back the p_navigation between goigng to other screens until a player quits or uses the p_navigation screens start day button to jump to start_day label