So I found this code online and wanted to edit it slightly (I'm quite new to Python):
Code: Select all
init python:
class day_time(object):
def __init__(self):
self.day = 1 # set this to whatever starting day is
self.weekdays = ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"] # arrange these so first weekday goes first
self.time_of_day = ["8AM","9AM","10AM","11AM","12PM","1PM","2PM","3PM","4PM","5PM","6PM","7PM","8PM","9PM","10PM","11PM","12AM","1AM","2AM","3AM"] # add or remove to increase time of day slots
self.end_of_day = self.time_of_day[-1] # automatically picks last slot as end of day
@property
def weekday(self):
return self.weekdays[(self.day-1)%7]
@property
def time(self):
return self.time_of_day[0]
def advance(self, increment = 0, days = 0):
if not (increment + days): # no input
increment = 1
if days: # add to increment by length of time_of_day
increment += days * len(self.time_of_day)
while increment > 0: # loop through increments to shift timeslot and days forward
if self.time_of_day[0] == self.end_of_day:
self.day += 1
self.time_of_day.append(self.time_of_day.pop(0))
increment -= 1 # reduce incrememnt to escape loop after enough runs
default clock = day_time()
Code: Select all
clock.advance()
Code: Select all
clock.advance(3)
So currently if my player does something at 3am that advances the time by 3 hours, the day increases but instead of starting at 8am, they of course start at 10am.
I want to be able to add on to this a system so that if the player does something that advances time past 3am, they get a message that says "It's late so you go to sleep", and then increases the day, but sets the time to 8AM.
Long shot, but could anyone help me with this, nothing I've tried works.
cheers!