Hello friends,
After reaching out to this forum for help several times now and always being kindly assisted, I would like to try again.
I have the following problem:
I want to trigger an event after a certain number of days, for example:
I know that this code doesn't quite work, it's just an example. Since I would like to use this function frequently in my game, I would like to make it as reusable as possible.
I am already using a custom daytime file for my game, which I will attach as it may be important.
Maybe someone knows the solution, I myself am a beginner in programming.
Thank you in advance.
After reaching out to this forum for help several times now and always being kindly assisted, I would like to try again.
I have the following problem:
I want to trigger an event after a certain number of days, for example:
Code:
label last_talk:
show endpicture001
get current day
if currentday +3 trigernr3 = True
return
I am already using a custom daytime file for my game, which I will attach as it may be important.
Code:
## tables used by CurrentDayTime class
define dow_names=[
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
"Sunday",
]
define dow_short_names=[
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat",
"Sun",
]
define tod_names=[
"Morning",
"Afternoon",
"Evening",
"Night",
]
define tod_image_suffix=[
"_morning",
"_afternoon",
"_evening",
"_night",
]
init python:
def display_new_tod():
## make sure we queue/show it only once, even if now.day_advance() was called
if "display_new_tod" not in queued_events:
queued_events.append("display_new_tod")
def process_time_advanced():
## this function is called to update other parts of game when game time is advanced
## called once for every tod passed
## advance_quests()
## advance_characters()
display_new_tod()
class CurrentDayTime(object):
def __init__(self,start_day=1,start_tod=0):
super(CurrentDayTime,self).__init__()
self.day=start_day
self.tod=start_tod
## will return number of day-of-week, Monday is 0, Saturday is 5, Sunday is 6
@property
def dow(self):
return (self.day-1)%7
## will return name of day-of-week, Monday, Saturday, Sunday
@property
def dow_name(self):
return dow_names[self.dow]
## will return short name of day-of-week, Mon, Sat, Sun
@property
def dow_short_name(self):
return dow_short_names[self.dow]
## will return name of time-of-day, Morning, Evening
@property
def tod_name(self):
return tod_names[self.tod%len(tod_names)]
## will return image suffix associated with current time-of-day, used to find most appropriate image
@property
def tod_image_suffix(self):
return tod_image_suffix[self.tod]
## advance time, by 1 tod by default
## will switch to new day when overlapping
## will call process_time_advanced function every tod advance
def advance(self,time_to_pass=1):
while time_to_pass>0:
time_to_pass-=1
self.tod+=1
if self.tod>=len(tod_names):
self.day+=1
self.tod=0
process_time_advanced()
## will advance time to next(by default) day, first tod(morning)
def day_advance(self,days_to_pass=1):
tods_to_pass=days_to_pass*len(tod_names)-self.tod
self.advance(tods_to_pass)
## instance can be called to check current day/time
## can check day number, day of week, time of day and combinations
## if one of arguments is list/tuple then check if any element inside is valid
## now("morning") will check if current time-of-day is morning
## now(5) will check if current day is 5
## now(10,"evening") will check if current day is 10 and current tod is evening
## now(["morning","afternoon"],["saturday","sunday"]) will check if it is
## morning or after noon of saturday or sunday
def __call__(self,*args):
for arg in args:
if isinstance(arg,basestring):
arg=arg.lower()
if arg not in (self.tod_name.lower(),self.dow_name.lower(),self.dow_short_name.lower()):
return False
elif isinstance(arg,(list,tuple)):
arg_list=arg
found=False
for arg in arg_list:
if isinstance(arg,basestring):
arg=arg.lower()
if arg in (self.tod_name.lower(),self.dow_name.lower(),self.dow_short_name.lower()):
found=True
else:
if arg==self.day:
found=True
if not found:
return False
else:
if arg!=self.day:
return False
return True
default now=CurrentDayTime()
## labels to be used by HUD during roaming mode
## avoid calling now.advance() directly from HUD as rollback/saving may become quirky
label advance_time:
$now.advance()
return
label advance_day:
$now.day_advance()
return
style new_tod_title:
color "#FFF"
size 64
text_align 0.5
align (0.5,0.5)
## black bg+white "TIME-OF-DAY"
label display_new_tod:
scene black with Dissolve(0.25)
if now("morning"):
show expression Text(now.dow_name+"\n"+now.tod_name,style="new_tod_title") with Dissolve(0.25)
else:
show expression Text(now.tod_name,style="new_tod_title") with Dissolve(0.25)
pause 1.0
return
Maybe someone knows the solution, I myself am a beginner in programming.
Thank you in advance.