Class is not called.

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
suihakei
Newbie
Posts: 21
Joined: Sun Jun 23, 2019 12:12 pm
Contact:

Class is not called.

#1 Post by suihakei »

I saw the following article and changed the program code so that it can be executed as a class method.
viewtopic.php?t=16371

However, the code I created does not seem to be running.
I do not know the cause of this.

script.rpy

Code: Select all

call defines_characters
label start:
    show jun egao at center
    with dissolve
characters.rpy( game/defines/characters.rpy )

Code: Select all

label defines_characters:
    define jun = Character('jun', image='jun', color="#297b7e", ctc='ctc_blink', ctc_position='nestled', voice_tag='jun')
    $ autoImageLoader = store.AutoImageLoader('chara/')
    $ autoImageLoader.autoRegisterImages('jun/fuku/', 'jun')
auto_image_loader.rpy( game/utils/auto_image_loader.rpy )

Code: Select all

init python:
    class AutoImageLoader(object):
        def __init__(self, base_folder_path):
            self.base_folder_path = base_folder_path

        def autoRegisterImages(self, folder_path, name):
            path = self.base_folder_path + folder_path

            for file in renpy.list_files():
                if file.startswith(path) == False:
                    continue

                if file.endswith('.png'):
                    file_name = file.replace(path, '').replace('.png', '')
                    renpy.image(name + ' ' + file_name, Image(path + file, yanchor=400))
For example, if you run the following code, the picture will be displayed correctly.

Code: Select all

image jun egao = "chara/jun/fuku/egao.png"
show jun egao at center
with dissolve
How do I fix this?
If you know anything about this, please let me know.

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2400
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Class is not called.

#2 Post by Ocelot »

First of all. RenPy already has automatic image declaration:
https://www.renpy.org/doc/html/displayi ... -directory
https://www.renpy.org/doc/html/config.h ... tic_images

Second: game starts from start label. Your call statement is placed before start label and is not called when the game is started. Which wouldn't matter in the end, because renpy.image function shouldn't be called outside init phase.
< < insert Rick Cook quote here > >

suihakei
Newbie
Posts: 21
Joined: Sun Jun 23, 2019 12:12 pm
Contact:

Re: Class is not called.

#3 Post by suihakei »

Thank you for your answer!
I didn't know it was already implemented.
I will use it.

Post Reply

Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot]