[SOLVED] How do I initialize the module first (before init)?

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
span4ev
Regular
Posts: 105
Joined: Fri Jul 08, 2022 9:29 pm
itch: rpymc
Contact:

[SOLVED] How do I initialize the module first (before init)?

#1 Post by span4ev »

I have a basic scripts.rpy file in which I create an instance of the class:

Code: Select all

init:
    $ game = Game()
And there is a separate file (game.rpy) in which this class is described:

Code: Select all

init python:
    class Game:
        def __init__(self):
        	pass
I get the error that "name 'Game' is not defined". The Init in the main file loads before the class "sees" it, and what's most annoying about Renpy (most annoying, inconvenient and horrible) is that Renpy crashes and closes. It always kills me... But that's not the point.

For python, you need to include additional files (modules) and I would do so at the beginning of the document:

Code: Select all

import game
But Renpy reads all files at once. But it turns out that they are read in order, so that when you try to create an instance of a class, it doesn't exist yet. How do I initialize the module first? I've seen something like "init python -1" or something like that, but I can't find an example or description of how that works.
Last edited by span4ev on Wed Nov 30, 2022 3:59 pm, edited 1 time in total.

User avatar
PyTom
Ren'Py Creator
Posts: 16088
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: How do I initialize the module first (before init)?

#2 Post by PyTom »

The number goes between init and python, so

Code: Select all

init:
    $ game = Game()

Code: Select all

init -1 python:
    class Game:
        def __init__(self):
        	pass
will work. The blocks are run from low to high, and -999 to 999 are reserved for creators.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

span4ev
Regular
Posts: 105
Joined: Fri Jul 08, 2022 9:29 pm
itch: rpymc
Contact:

Re: How do I initialize the module first (before init)?

#3 Post by span4ev »

Thank you so much, I'm happy! (I should have asked that a long time ago...)

Post Reply

Who is online

Users browsing this forum: Google [Bot], VESTED