Variable-length parameter lists and the Animation class

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
Ignis_Umbrae
Newbie
Posts: 2
Joined: Fri Jul 24, 2009 8:57 pm
Contact:

Variable-length parameter lists and the Animation class

#1 Post by Ignis_Umbrae »

Greetings!

To make life a little easier for myself, I wrote a small snippet of Python which retrieves all images from a directory, taking an animation speed and returning a tuple (stored in tools.py):

Code: Select all

import os

def animList(path,speed):
    alist = []
    for f in os.listdir(path): alist = alist+[f,speed]
    return tuple(alist)
However, when I go to use this with Python's asterisk notation for variable-length parameter lists like so:

Code: Select all

init:
    $ import tools
    $ pw = Character(u"Phoenix",color="#ffffff")
    image pw point talk = Animation(*tools.animList("img/phoenix/pointing-t",0.16))
Ren'Py throws a syntax error. Why? The code works perfectly under the Python interpreter; what is Ren'Py baulking over? Even if I first assign the result of calling tools.animList as above in a variable (x, say) and then call Animation(*x), a syntax error is thrown.

Any assistance very much appreciated. Thanks!

KimiYoriBaka
Miko-Class Veteran
Posts: 636
Joined: Thu May 14, 2009 8:15 pm
Projects: Castle of Arhannia
Contact:

Re: Variable-length parameter lists and the Animation class

#2 Post by KimiYoriBaka »

two things come to mind:
1. are you normally allowed to use a variable containing a character as part of an image name? That seems like it would confuse renpy.

2. perhaps renpy doesn't like using asterisks that way. If that's the case, it might work to define the animation separately in a statement starting with a $, then set it equal to point talk.

Ignis_Umbrae
Newbie
Posts: 2
Joined: Fri Jul 24, 2009 8:57 pm
Contact:

Re: Variable-length parameter lists and the Animation class

#3 Post by Ignis_Umbrae »

Edit 3: the problem appears to be to do with relative paths. Specifying the full path (here "C:/renpy-6.9.2/PWAAish/game/img/phoenix/pointing-t/") fixes the problems, but using the relative path ("img/phoenix/pointing-t") causes an error. Does tools.py implicitly run from a different base path to the main script or something?

georgmay
Regular
Posts: 131
Joined: Sun Feb 08, 2009 2:00 pm
Projects: Restriction
Location: Belarus,Minsk
Contact:

Re: Variable-length parameter lists and the Animation class

#4 Post by georgmay »

You need a full path.
Maybe this will help you.

Code: Select all

 image pw point talk = Animation(*tools.animList(config.gamedir + "/img/phoenix/pointing-t",0.16))
and, i think, import tools you need replace to

Code: Select all

init python:
    import tools
Returned

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot], half1-2moon