Problem with automatically loading files

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
User avatar
Sondre
Newbie
Posts: 18
Joined: Wed Dec 02, 2015 6:16 am
Projects: There's a Dinosaur in my Bed (working title)
Contact:

Problem with automatically loading files

#1 Post by Sondre »

Hello!

The other day I was testing out a way of playing animations in Renpy. Being fairly inexperienced, my simple method of doing it looked like this:

Code: Select all

image fireball:
    "spells/fireball000.png"
    0.06
    "spells/fireball001.png"
    0.06
    "spells/fireball002.png"
    0.06
    "spells/fireball003.png"
    0.06
    "spells/fireball004.png"
    0.06
    "spells/fireball005.png"
    0.06
    "spells/fireball006.png"
    
I showed this to a friend of mine and he suggested I implement a code that would automatically load all the images without me having to list them all. However, we couldn't get it to work as Renpy just threw error after error at us. So now I have taken to these forums to seek guidance.


My friend's code looked something like this:

Code: Select all

init python:
    def load_anim(location, lenght, interval):
       image img = None
       for i in range(length):
            img.append("{0}{1:03d}.png".format(location, i))
            img.append(interval)
       return img

$ image fireball = load_anim("spells/fireball", 24, 0.06)
Is there a way to make this concept work? Any and all help is much appreciated!
Last edited by Sondre on Thu Jun 21, 2018 6:38 am, edited 1 time in total.

User avatar
Milkymalk
Miko-Class Veteran
Posts: 753
Joined: Wed Nov 23, 2011 5:30 pm
Completed: Don't Look (AGS game)
Projects: KANPEKI! ★Perfect Play★
Organization: Crappy White Wings
Location: Germany
Contact:

Re: Problem with automatically loading files

#2 Post by Milkymalk »

The problem lies here: "image img = None" is NOT Python and can not be used inside a function. It is Ren'py script and can only used outside of functions or python blocks.
You need to be aware that there are actually four(!) languages used by Ren'py: Python, Ren'py script, screen language and ATL. While some things from Python, like loops, can be used in the others, the opposite is not true. Python has no idea how to interpret expressions from the three script languages.

Next: You can't .append a None type variable. .append is a method for lists only.

Also, the return statement needs to be indented one more instance. It belongs to the sub-block of def.

Unfortunately I can not help you with your initial problem. You can try using a for-loop directly inside the image declaration, but I doubt that it will work.
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)

Post Reply

Who is online

Users browsing this forum: Google [Bot]