Automatic character, background, etc. image defining script

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Message
Author

User avatar
Zetsubou
Veteran
Posts: 443
Joined: Wed Mar 05, 2014 1:00 am
Completed: See my signature
Github: koroshiya
itch: zetsuboushita
Contact:

Re: Automatic character, background, etc. image defining scr

#32 Post by Zetsubou » Sun Aug 02, 2015 3:26 pm

You can't do that with python methods. You can make arguments optional by giving them a default value, but you can't insert a value by itself. (ie. "def define_characters(characterImageFolder='sprites/')" would work, but "def define_characters('sprites/')" won't)

You should be calling the method with your own parameters, not editing the method directly. Only the character indexes method should be edited.
Put the define_characters method back to how it was, then call "define_characters('sprites/')" at the end of the script.
Finished games
-My games: Sickness, Wander No More, Max Massacre, Humanity Must Perish, Tomboys Need Love Too
-Commissions: No One But You, Written In The Sky, Diamond Rose, To Libertad, Catch Canvas, Love Ribbon, Happy Campers

Working on:
Sable's Grimoire + several VN writing commissions

Image

Ladycardboard
Newbie
Posts: 22
Joined: Tue Jul 28, 2015 6:17 pm
Contact:

Re: Automatic character, background, etc. image defining scr

#33 Post by Ladycardboard » Tue Aug 04, 2015 4:02 pm

i put the code back in fresh after deleting the whole thing with my stupid earlier mistakes in it. Got another error after removing the '#' in front of the example you put at the bottom.

http://imgur.com/w4lCYEh

User avatar
Zetsubou
Veteran
Posts: 443
Joined: Wed Mar 05, 2014 1:00 am
Completed: See my signature
Github: koroshiya
itch: zetsuboushita
Contact:

Re: Automatic character, background, etc. image defining scr

#34 Post by Zetsubou » Tue Aug 04, 2015 6:37 pm

It looks like your get_character_indexes method needs updating.
That error should mean the script found an "ears" directory in one of your characters, but it wasn't defined in the above method.

What's your get_character_indexes method currently look like? And what is the directory structure you're using?
Finished games
-My games: Sickness, Wander No More, Max Massacre, Humanity Must Perish, Tomboys Need Love Too
-Commissions: No One But You, Written In The Sky, Diamond Rose, To Libertad, Catch Canvas, Love Ribbon, Happy Campers

Working on:
Sable's Grimoire + several VN writing commissions

Image


Hseo
Newbie
Posts: 24
Joined: Thu Sep 24, 2009 10:42 am
Completed: High School Life:HSL
Deviantart: greeeed
Contact:

Re: Automatic character, background, etc. image defining scr

#36 Post by Hseo » Fri Mar 17, 2017 11:50 am

Thanks.
It help to save a lot of my time.

And for people with error as this one
Ladycardboard wrote:Tried it and got this error:

Image
The answer is simple.
put define_characters("comm", 1) inside same the python code like this.

Code: Select all

init python:
    import os
    def define_characters(characterImageFolder, excludeFirstXFolders=0, flip=True):
        for path in renpy.list_files():
            if path.startswith(characterImageFolder + "/"):
                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_characters("images", 1)
And not like this

Code: Select all

init python:
    import os
    def define_characters(characterImageFolder, excludeFirstXFolders=0, flip=True):
        for path in renpy.list_files():
            if path.startswith(characterImageFolder + "/"):
                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))
    
init:                
    image bg testing1 = "images/bg 0001.jpg"
    define_characters("images", 1, False)
Yes, I made the same error as him :mrgreen:

User avatar
ariasune
Newbie
Posts: 3
Joined: Sun Nov 19, 2017 6:00 am
Tumblr: ariasune
Deviantart: ariasune
Contact:

Re: Automatic character, background, etc. image defining script

#37 Post by ariasune » Sun Nov 19, 2017 9:30 am

I'm a beginner, so I'm concerned I'm making a rookie mistake that can be spotted in a split second. That being said, I'm having a hard time working this script into even the very base script, with none of the images being defined.

Oddly enough it seemed to work for a bit, but then refused to work later, even after reverting everything to the state when it was working. I really feel I must be missing something, and I hate to bother people.

My file directory for sprites is as follows:

game/images/sprites/[character]/[emotion].png

My script file is as follows:

Code: Select all

init python:
    import os
    def define_characters(images, excludeFirstXFolders=0, flip=True):
        for path in renpy.list_files():
            if path.startswith(images + "/"):
                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_characters("sprites", 1)
    
init:
    $ k = Character("Kaiba")

image base = "base.jpg"

label start:

    scene base
    show kaiba smile

    k "A puppy die everytime I smile."

return

User avatar
Zetsubou
Veteran
Posts: 443
Joined: Wed Mar 05, 2014 1:00 am
Completed: See my signature
Github: koroshiya
itch: zetsuboushita
Contact:

Re: Automatic character, background, etc. image defining script

#38 Post by Zetsubou » Sun Nov 19, 2017 3:14 pm

I really haven't touched this script or checked this thread in a long time, but at a glance, I think your problem is the

Code: Select all

define_characters("sprites", 1)
line.
Your sprites are in images/sprites, so your function should be

Code: Select all

define_characters("images/sprites", 1)
That being said, if you're using the images directory anyway, and you don't need image flipping or to perform any other functions on the images, you might as well get rid of this script and just use Renpy's automatic image defining mechanism.
eg. instead of: game/images/sprites/[character]/[emotion].png
have: game/images/sprites/[character]/[character] [emotion].png

"[character] [emotion].png", inside of the "images" directory, will automatically be defined by Renpy, without the need for any script like this.
Finished games
-My games: Sickness, Wander No More, Max Massacre, Humanity Must Perish, Tomboys Need Love Too
-Commissions: No One But You, Written In The Sky, Diamond Rose, To Libertad, Catch Canvas, Love Ribbon, Happy Campers

Working on:
Sable's Grimoire + several VN writing commissions

Image

User avatar
ariasune
Newbie
Posts: 3
Joined: Sun Nov 19, 2017 6:00 am
Tumblr: ariasune
Deviantart: ariasune
Contact:

Re: Automatic character, background, etc. image defining script

#39 Post by ariasune » Tue Nov 21, 2017 12:50 am

Thank you very much. I've opted to go with Renpy's automatic image defining mechanism, since I'm not making use of flips. I appreciate you taking the time to glance over the code and solve the issue, as well as offer an alternative.

Again, thank you very much!

Post Reply

Who is online

Users browsing this forum: No registered users