init python:
class MyTimePassing( renpy.python.RevertableObject ):
# All the periods of the day, and associated number of actions
# available for this period.
dayPeriod = [ "Day", "Afternoon", "Evening" ]
actionByPeriod = [ 10, 10, 10 ]
# All the days of the week, and associated period where the day start
# for the player.
dayOfWeek = [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ]
# Reminder, the first indice of a list is 0.
startOfDOW = [ 0, 2, 2, 2, 2, 2, 0 ]
# The live values. The game start at /Day/ on a Sunday, with 10 action
# points.
actualPeriod = 0
actualDOW = 0
actualAP = 10
@property
def period( self ):
return self.dayPeriod[self.actualPeriod]
@property
def day( self ):
return self.dayOfWeek[self.actualDOW]
@property
def AP( self ):
return self.actualAP
def nextPeriod( self ):
if self.actualPeriod == len( self.dayPeriod ) -1:
self.nextDay()
else:
self.actualPeriod += 1
self.actualAP = self.actionByPeriod[self.actualPeriod]
def nextDay( self ):
if self.actualDOW == len( self.dayOfWeek ) -1:
self.actualDOW = 0
else:
self.actualDOW += 1
self.actualPeriod = self.startOfDOW[self.actualDOW]
self.actualAP = self.actionByPeriod[self.actualPeriod]
def dayIs( self, expected ):
return expected == self.dayOfWeek[self.actualDOW]
def periodIs( self, expected ):
return expected == self.dayPeriod[self.actualPeriod]
def canUseAP( self, expected=1 ):
return self.actualAP >= expected
def useAP( self, number=1 ):
# Validate that the player have enough action points
if self.canUseAP( number ) is False:
return False
self.actualAP -= number
return True
def haveAP( self ):
return self.canUseAP()
# Create the object to be rollback compliant and savable.
default timePassing = MyTimePassing()
# Minimalist HUD
screen timeHUD:
vbox:
text "Today is [timePassing.day]."
text "It's [timePassing.period] time."
text "You have [timePassing.AP] action points."
# And here's an example of use
label start:
# This will be the prologue
"This is the prologue..."
label dayLoop:
show screen timeHUD
if timePassing.dayIs( "Sat" ):
jump Saturday
if timePassing.dayIs( "Sun" ):
jump Sunday
else:
jump Weekday
label Weekday:
"Hey, it's a weekday."
menu menuLoop1:
"Invite the girl to a restaurant":
if not timePassing.canUseAP( 5 ):
"Sorry, you don't have enough action points to do this."
else:
$ timePassing.useAP( 5 )
"You go to a fancy place."
"Kiss the girl":
if not timePassing.useAP( 2):
"You don't have enough actions points for this."
else:
"She liked it."
"Hug the girl":
# By default the number of AP is 1.
if not timePassing.useAP():
"You don't have enough actions points for this."
else:
"Apaprently she wanted more that a simple hug."
if timePassing.haveAP():
jump menuLoop1
jump Bedtime
# SATURDAY
label Saturday:
"Hey, it's Saturday."
menu menuLoop2:
"Invite the girl to a restaurant":
if not timePassing.canUseAP( 5 ):
"Sorry, you don't have enough action points to do this."
else:
$ timePassing.useAP( 5 )
"You go to a fancy place."
"Kiss the girl":
if not timePassing.useAP( 2):
"You don't have enough actions points for this."
else:
"She liked it."
"Hug the girl":
# By default the number of AP is 1.
if not timePassing.useAP():
"You don't have enough actions points for this."
else:
"Apaprently she wanted more that a simple hug."
if timePassing.haveAP():
jump menuLoop2
if dayPeriod == Evening:
jump Bedtime
menu:
"Continue with what you're doing":
$ timePassing.nextPeriod()
jump menuLoop2
"Do something else":
jump Somethingelse
label Sunday:
"Hey, it's Sunday."
menu menuLoop3:
"Invite the girl to a restaurant":
if not timePassing.canUseAP( 5 ):
"Sorry, you don't have enough action points to do this."
else:
$ timePassing.useAP( 5 )
"You go to a fancy place."
"Kiss the girl":
if not timePassing.useAP( 2):
"You don't have enough actions points for this."
else:
"She liked it."
"hug the girl":
# By default the number of AP is 1.
if not timePassing.useAP():
"You don't have enough actions points for this."
else:
"Apaprently she wanted more that a simple hug."
if timePassing.haveAP():
jump menuLoop3
if dayPeriod == Evening:
jump Bedtime
menu:
"Continue with what you're doing":
$ timePassing.nextPeriod()
jump menuLoop3
"Do something else":
jump Somethingelse
label Somethingelse:
"You do something else"
label Bedtime:
"It's late. Time for bed."
$ timePassing.nextDay()
jump dayLoop
[/quote]
For the weekend, where there is more than one dayperiod, I wanted to have an option to continue (ie. move on to the next period) or do something else. However, after the expiry of the Evening dayperiod, I want to go to sleep right away. I tried to do this with an if statement (if dayPeriod == Evening:) but dayPeriod doesn't seem to have been defined? I'm a bit unclear on that.
The other thing I want, and should be able to figure out but can't for some reason, is how to start on a Monday?
Thanks in advance for the help.