Ren'Py Question about Ren'py image scripting.

Klauw1988

Member
Aug 23, 2020
176
235
Hello everyone,

I recently started with my own novel. I've watch some tutorials and i was wondering something. Do you need to add each image on a new line or is there also a script that adds a full whole submap in one script instead of each image on a separately line. My next prologue will be even bigger with more pictures. And then the main game begins.

For example, i have now the lines,

image prologue_1 = "images/Prologue day 1/Day 1.1.jpg"

to

image prologue_59 = "images/prologue day 1/Day 1.59.jpg"

Can't i just add all those images with just one script, instead of 59 separately once?
 

barotok

New Member
Apr 30, 2019
13
10
I've used this in my testing and it seems to work fine
Python:
init python :
    import os

  

    def define_images(imageFolder, excludeFirstXFolders=0, flip=True):
            for path in renpy.list_files():
                if path.startswith(imageFolder):
                    path_list = path.split("/")
                    path_list[-1] = os.path.splitext(path_list[-1])[0]
                    path_list = tuple(path_list[excludeFirstXFolders:])
                    renpy.image(path_list, path)
                    if flip:
                        renpy.image(path_list + ("flip", ), im.Flip(path, horizontal=True))
                        
    define_images('images/scenes/',2,False)
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,611
2,258
A much better solution would have been to just name your files to match their intended "RenPy name".

images/Prologue day 1/prologue_1.jpg thru images/Prologue day 1/prologue_59.jpg.

That way you wouldn't need any extra coding... as RenPy automatically creates image statements for all image files within the /images/ directory and it's sub folders already.

You'd simply code scene prologue_1 with dissolve without coding any image statements manually.

As an aside, I would caution against using any uppercase or space characters in your filenames (or variable names either). It'll work - but it'll cause you headaches in the future unless you are VERY consistent and organized. Use underscores instead of spaces would be my suggestion and lowercase only.
I already notice that you are already mixing "day" and "Day" within the full filename. So yeah...

Additionally you could shorten the names a bit without losing any information and save yourself a lot of typing during the lifecycle of your game. For example, Day could become d. Nothing is really lost. But I understand if you've already developed the habit and don't want to change it.

But maybe images/prologue/d01_059.jpg instead of images/Prologue day 1/Day 1.59.jpg.
Using leading zeroes is a habit of mine, because I assume most games will have more than 9 days and I don't like to assume a single day will always contain less than 100 unique images.

I would have also suggested at this point that you could have just used the displayable names RenPy has already automatically created for you, by doing something like scene day 1.1 with dissolve. Unfortunately RenPy doesn't like displayable names with fullstops/periods in them. So the 1.1 within the filename breaks things for RenPy.

But images/Prologue day 1/Day 1_59.jpg -> scene day1_59 with dissolve would work just fine without a separate image statement.
(the filenames are converted to lowercase by RenPy's automatic process... another reason to avoid mixed case filenames - to avoid any confusion).