For apart of the game I'm creating, I need the player to be able to press a "Do Schedule" button and then have the schedule they set up run. I've had issues with buttons not working with functions before and have gotten around it by making what I call a "function class".
It lets me provide an object to an action and get it to work by using __call__( self ). However, even when using a __call__( self ) it doesn't work. Here's the relevant code.
Code:
## The screen the text button is found in
## I'm cutting out the code above and below the section
frame xpos 310 ypos 200:
hbox spacing 2:
vbox:
textbutton "Study" action Show( "studyMenu" )
textbutton "Events" action Show( "eventsMenu" )
textbutton "Training" action Show( "trainingMenu" )
textbutton "Do Schedule" action Calendar()
## Calendar Class
## I'm cutting out most of the code for this one as well. It's a full class though with constructors and several other functions
## The __call__
def __call__( self ):
self.runSchedule( ) ##This is the function I want the button to execute
## This is the runSchedule( self ) function, just in case
def runSchedule( self ):
currentDay = self.getDayIndex( )
currentMonth = self.getMonthIndex( DAY, YEAR )
## This loops through the day, doing each action.
## After every action, TIMEPERIOD is incremented by some amount
## TIMEPERIOD can start each day from 1 to 3
for period in range( 1, 4 ):
if( TIMEPERIOD == 1 ):
self.runAction( self.Calendar[currentMonth][currentDay].Morning )
elif( TIMEPERIOD == 2 ):
self.runAction( self.Calendar[currentMonth][currentDay].Afternoon )
elif( TIMEPERIOD == 3 ):
self.runAction( self.Calendar[currentMonth][currentDay].Evening )
elif( TIMEPERIOD == 4 ):
self.runAction( self.Calendar[currentMonth][currentDay].Night )
else:
self.nextDay( )
Any ideas on why this isn't working? According to the documentation this should be kosher,
Code:
Many of the displayables created in the screen language take actions as arguments. An action is one of three things:
A callable python object (like a function or bound method) that takes no arguments.
An object of a class that inherits from the Action class.
A list of other Actions.
Source:
http://www.renpy.org/doc/html/screen_py ... ml#actions So, this is sort of leaves me with the questions...
Am I using the __call__ wrong so that is why the button is remaining insensitive? If so, any idea on how to fix it?
Is my only choice to have the Calendar class inherit from Action class? I'd like to avoid this if possible because I'm not sure what I need to do exactly.