Just to clarify, when you're writing programming code - unless you explicitly write the code that tells the program to do something specific, it won't automatically know what you want. Your program also won't know what you're trying to do by the name of the variables, because it has no intelligence and it can't translate and interpret meanings from your code - it just compiles the instructions you give it.
With that said, you'll need to write your own function or classes to do what you want: and the simplest way is to use the mod operator %: e.g. 12 % 7 = 5
What the mod operator does is, it returns the remainder of your first value after being divided by the second value. e.g. with 1 % 7, 7 goes into 1 exactly 0 times, with 1 as a remainder. 12 % 7: 7 goes into 12 exactly 1 time, with a remainder 5.
This is what will reset your values to 0, so to speak. In programming, we usually count numbers from 0 - there're lots of benefits in programming terms, this being one of them: 7 % 7 == 0 because 7 goes into 7 once, with a remainder 0. So if you're counting 7 days, you'd actually count from 0 to 6. The cool thing is, since lists start at index 0, you can have:
Code: Select all
define day_of_week = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
default day = 0
default dow = day_of_week[day]
label start:
"[dow]" # Shows "Sun"
$ day += 12
$ dow = day_of_week[day%7]
"[dow]" # Shows "Fri"
return
In reality, you'd probably want to create a function or better yet an object to manage that. The benefit of using mod here is that you are now working out the day of the week from a single variable - meaning your day and day of week can't possible fall out of sequence anywhere in your code.
You can use the same principle with time of day, but you'd probably also want to check whether you need to start a new day as well.
Code: Select all
define day_of_week = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
define time_of_day = ["Morning", "Noon", "Afternoon", "Evening", "Night"]
default day = 0
default tod = 0
default dow = day_of_week[day]
default time_now = time_of_day[tod]
init python:
def advance_time(_time = 1):
global tod, time_now, time_of_day, day
new_days = (tod + _time) // 5 # // returns floored divisions, in other ways how many times the divider goes into the value, ignoring remainders
tod = (tod + _time) % 5
time_now = time_of_day[tod]
advance_day(new_days) # add new days
def advance_day(_day = 1):
global day, dow, day_of_week
day += _day
dow = day_of_week[day%7]
label start:
"[dow]"
$ advance_day(12)
"[dow]"
"[time_now]"
$ advance_time(6)
"[dow] [time_now]"
It may be quite a lot to take in if you're unfamiliar with programming, so please feel free to ask questions. I need to head off for a bit but will try to answer if I'm able to.