Lemma Soft Forums

Supporting creators of visual novels and story-based games since 2003.


Visit our new games list, blog aggregator, IRC, and wiki.
Activation problem? Email [email protected]
It is currently Fri May 24, 2013 1:39 pm

All times are UTC - 5 hours [ DST ]


Forum rules


Ask questions about one topic per thread, and use a descriptive subject. "NotImplemented error in script.rpy" is a good subject, "Tom's problems" is not. Remember to include all of traceback.txt or error.txt when reporting a problem, as well as the relevant lines of script. Use the [code] tag to format scripts.



Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Fri Apr 13, 2012 5:39 pm 
Newbie
User avatar

Joined: Sun Jul 10, 2011 7:30 pm
Posts: 23
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.


Top
 Profile Send private message  
 
PostPosted: Fri Apr 13, 2012 6:36 pm 
Ren'Py Creator
User avatar

Joined: Mon Feb 02, 2004 10:58 am
Posts: 10778
Location: Kings Park, NY
Completed: Moonlight Walks
Projects: Ren'Py
Can you post more more of the code? The code is so elided, it's hard to tell what's elided and what's a real error.

Also, post why you think the code is wrong. (Any error message, or something like that.) Remember, we can't actually run it ourselves, easily.

You shouldn't need to use an Action.

_________________
Another Old-Fashioned Bishoujo Gamer
Supporting creators since 2004; Code > Drama
(When was the last time you backed up your game?)
"It is not the critic who counts; not the man who points out how the strong man stumbles, or where the doer of deeds could have done them better. The credit belongs to the man who is actually in the arena, whose face in marred by dust and sweat and blood; who strives valiantly; who errs, who comes short again and again, because there is no effort without error and shortcoming" - Theodore Roosevelt


Top
 Profile Send private message  
 
PostPosted: Fri Apr 13, 2012 6:37 pm 
Veteran
User avatar

Joined: Wed Nov 18, 2009 11:17 am
Posts: 359
Location: Germany
Completed: Loren
Projects: PS2
I think the problem is that you create a new Calender object every time the action is performed.
You can call the method directly with: action calender.runSchedule
Where calender is a variable containing your Calender object. The parentheses are omitted on purpose, since they are the usual way to call a function, but we want to leave that to Ren'Py.

_________________
Avatar created with this deviation by Crysa
Currently working on:
  • Winterwolves "Planet Stronghold 2" - RPG Framework: Phase II


Top
 Profile Send private message  
 
PostPosted: Fri Apr 13, 2012 7:52 pm 
Newbie
User avatar

Joined: Sun Jul 10, 2011 7:30 pm
Posts: 23
Thank you for the replies.

PyTom:

Sorry if I wasn't clear on what I believed was an error. The problem is that the text button remains insensitive despite having a command for an action. It's like it was never given an action in the first place. I'm trying to get the button to run the day's schedule, which is done by Calendar.runSchedule(). I think programming too long shuts off my ability to communicate sometimes.

I didn't post the full code because the Calendar class by itself is about 850 lines of code and many of the screens are easily 20 to 50 each as well. I tried to cut out stuff that didn't affect things to make it easier to read.

Anima:

I didn't know call created a new calendar every time it did that. It makes me wonder if the function classes I made will just lead to problems later on.

And thank you, I tried Calendar.runSchedule without the parenthesis and the button became sensitive. Would you mind if I asked why Calendar.runSchedule works but Calendar.runSchedule() does not? Also, if I wanted to have a function, let's call it, Calendar.makeSpiffy( X, Y ), would that be possible as well? If not, how would you do that?


Top
 Profile Send private message  
 
PostPosted: Fri Apr 13, 2012 8:15 pm 
Veteran
User avatar

Joined: Wed Nov 18, 2009 11:17 am
Posts: 359
Location: Germany
Completed: Loren
Projects: PS2
Simple, Ren'Py will pretty much go trough the list of action objects and calls the actions __call__ method. With function() in the list, Ren'Py will not get the function object, it gets the result of the __call__ method, which is normally None. And buttons without actions are by default insensitive.

To get the parameters you either have to define a subclass of action and put the parameter in the init method, or you use a list of actions and set the parameters to fields on the object, something like this: action (SetField(calender,"spiffyParmaters",(X,Y)), calender.gui_makeSpiffy)

where gui_makeSpiffy is the following:
Code:
def gui_makeSpiffy(self):
    self.makeSpiffy(self.spiffyParmaters[0],self.spiffyParmaters[1])


That's the way I did things in Loren.

_________________
Avatar created with this deviation by Crysa
Currently working on:
  • Winterwolves "Planet Stronghold 2" - RPG Framework: Phase II


Top
 Profile Send private message  
 
PostPosted: Tue Apr 17, 2012 12:37 am 
Newbie
User avatar

Joined: Sun Jul 10, 2011 7:30 pm
Posts: 23
I see, that's a little weird, but I think I got it. Thanks for answering that question for me.


Top
 Profile Send private message  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


Who is online

Users browsing this forum: Donmai, Mink


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Protected by Anti-Spam ACP
Powered by phpBB® Forum Software © phpBB Group