jsfehler / renpy-encyclopaedia

A Ren'Py plugin for creating an Encyclopaedia/Glossary/Bestiary or similar system.
https://renpy-encyclopaedia.readthedocs.io/
MIT License
58 stars 6 forks source link

NameError: name 'Encyclopaedia' is not defined #15

Open WestRodri opened 1 week ago

WestRodri commented 1 week ago

I dragged an droped the Encyclopaedia folder from the github into the main and used the example code:

init python:
    greek_mythology = Encyclopaedia(name="Greek Mythology")

screen open_encyclopaedia():
    textbutton "Open Encyclopaedia":
        action ShowMenu(greek_mythology.list_screen, greek_mythology)

label start:
    show screen open_encyclopaedia

    "I sure love having a game with an encyclopaedia."

    return

but it gives me an error "NameError: name 'Encyclopaedia' is not defined". Looking through the Encyclopaedia folder files I get quite a few warnings pertaining to imports. A lot of them say "Import "renpy" could not be resolvedPylance[reportMissingImports]"

is there something that isn't compatible? I'm using Renpy 8.3.2.

WestRodri commented 1 week ago

Ok I imported the "lib" and "renpy" folders from the repo to the game folder. Most of the warnings went away. Now the only warning left is on from renpy.store import lines. What am I missing?

jsfehler commented 1 week ago

What does "into the main" mean? Do you mean the main directory of your project? If the Encyclopaedia object is not found it means Ren'Py has not seen the code. Did you place the files outside the game directory?

You cannot naively use a python type checker on a Ren'Py project. Ren'Py is not a python project and has no type checking available. If you use a type checker on embedded python code it's your responsibility to configure mocks and stubs appropriately for whichever files you want to type check. You can use this project as a reference but I offer no support for type checking your project.

WestRodri commented 1 week ago

Apologies I should have been more specific, I appreciate you replying. I dragged the "encyclopaedia" folder that was in the repo into the "game" folder of my project.

From there I used the example code and gives me an immediate error ""NameError: name 'Encyclopaedia' is not defined"."

So renpy is not seeing the code even though it's in the game folder. Unfortunately this feels like something you can't help me with from what you've said.

jsfehler commented 1 week ago

Ren'Py loads files in alphabetical order. If the encyclopaedia files are loaded after the file which creates the Encyclopaedia instance, it will cause an error.

Try:

init 1 python when you create an Encyclopaedia in order to force load order