Accessing a class list
Posted: Sun Jun 13, 2021 5:40 am
Hey, I'm using a simple day/time script found here viewtopic.php?t=49177
More precisely I'm talking about this list found here at self.time_of_day:
I have a free roam mode in my game and want to make events run at certain times of the day with certain conditions fulfilled. So far I've been simply using:
But honestly this is becoming a bit of a pain already with only a few events. I've got too much spaghetti code already I'd like to keep things a bit tidier. Since it's a list I assumed the entries have numbers attached and morning equals 0, noon = 1 etc. and I could just use
To trigger the event at anything but night but it doesn't work and does nothing.
The only thing that does work this way is
But this just triggers the event all the time.
FYI: Yes, I'm bad at python.
More precisely I'm talking about this list found here at self.time_of_day:
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 = ["morning", "noon", "evening", "night"] # 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
if chara_story2 ==1 and chara_friendship >=2 and clock.time == "morning"
or chara_story2 ==1 and chara_friendship >=2 and clock.time == "noon"
Code: Select all
if clock.time <=2
The only thing that does work this way is
Code: Select all
if clock.time >=0 (or any number of this matter)
FYI: Yes, I'm bad at python.