Encyclopaedia / Bestiary Framework

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
Human Bolt Diary
Regular
Posts: 97
Joined: Fri Oct 11, 2013 12:46 am
Contact:

Re: Encyclopaedia / Bestiary Framework

#46 Post by Human Bolt Diary » Tue Sep 11, 2018 8:43 am

In this case, what you want is:

Code: Select all

textbutton _("Encyclopedia") action ShowMenu("encyclopaedia_list", your_new_encyclopaedia)
AERenoir wrote:
Tue Sep 11, 2018 5:51 am
After creating entries I tried to make a button to open the Encyplopedia.

I inserted the Encyclopedia button at the start menu. The documentation says it needs two arguments, but I'm not sure what the format is supposed to be.
I wrote it like this, and it's obviously wrong:

Code: Select all

 textbutton _("Encyclopedia") action ShowMenu("encyclopaedia_list",Encyclopaedia)
The sample entry, as copy-pasted from the documentation

Code: Select all

init python:
    your_new_encyclopaedia = Encyclopaedia()




python:
    your_new_encyclopaedia = Encyclopaedia()

        
        
    about_zeus = EncEntry(
    parent=your_new_encyclopaedia,
    name="Zeus",
    text=[
        "Zeus is the sky and thunder god in ancient Greek religion, who ruled as king of the gods of Mount Olympus."
        " His name is cognate with the first element of his Roman equivalent Jupiter."
        " His mythologies and powers are similar, though not identical, to those of Indo-European deities such as Indra, Jupiter, Perun, Thor, and Odin."
    ],
    viewed_persistent=True,
)
       
        

User avatar
AERenoir
Veteran
Posts: 300
Joined: Fri May 27, 2011 8:23 pm
Contact:

Re: Encyclopaedia / Bestiary Framework

#47 Post by AERenoir » Tue Sep 11, 2018 11:24 am

Something's not working again. Did I create the Encyclopedia wrong?
I put the Encyclopaedia entry block (the one with Zeus and stuff) At the top of script.rpy.

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/encyclopaedia_screens.rpy", line 90, in execute
    screen encyclopaedia_list(enc):
  File "game/encyclopaedia_screens.rpy", line 90, in execute
    screen encyclopaedia_list(enc):
  File "game/encyclopaedia_screens.rpy", line 94, in execute
    window:
  File "game/encyclopaedia_screens.rpy", line 97, in execute
    vbox:
  File "game/encyclopaedia_screens.rpy", line 106, in execute
    frame:
  File "game/encyclopaedia_screens.rpy", line 110, in execute
    hbox:
  File "game/encyclopaedia_screens.rpy", line 113, in execute
    text "{} Complete".format(enc.labels.percentage_unlocked)
  File "game/enc.rpy", line 1071, in percentage_unlocked
    percentage_unlocked = int(self.encyclopaedia.percentage_unlocked)
  File "game/enc.rpy", line 719, in percentage_unlocked
    'Cannot calculate percentage unlocked of empty Encyclopaedia'
ZeroDivisionError: Cannot calculate percentage unlocked of empty Encyclopaedia

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "renpy/common/_layout/screen_main_menu.rpym", line 28, in script
    python hide:
  File "F:\Desktop\Ren'py\renpy-7.1.0-sdk\renpy\ast.py", line 882, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "F:\Desktop\Ren'py\renpy-7.1.0-sdk\renpy\python.py", line 1913, in py_exec_bytecode
    exec bytecode in globals, locals
  File "renpy/common/_layout/screen_main_menu.rpym", line 28, in <module>
    python hide:
  File "renpy/common/_layout/screen_main_menu.rpym", line 35, in _execute_python_hide
    ui.interact()
  File "F:\Desktop\Ren'py\renpy-7.1.0-sdk\renpy\ui.py", line 289, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "F:\Desktop\Ren'py\renpy-7.1.0-sdk\renpy\display\core.py", line 2662, in interact
    repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, **kwargs)
  File "F:\Desktop\Ren'py\renpy-7.1.0-sdk\renpy\display\core.py", line 3049, in interact_core
    root_widget.visit_all(lambda i : i.per_interact())
  File "F:\Desktop\Ren'py\renpy-7.1.0-sdk\renpy\display\core.py", line 521, in visit_all
    d.visit_all(callback, seen)
  File "F:\Desktop\Ren'py\renpy-7.1.0-sdk\renpy\display\core.py", line 521, in visit_all
    d.visit_all(callback, seen)
  File "F:\Desktop\Ren'py\renpy-7.1.0-sdk\renpy\display\core.py", line 521, in visit_all
    d.visit_all(callback, seen)
  File "F:\Desktop\Ren'py\renpy-7.1.0-sdk\renpy\display\core.py", line 521, in visit_all
    d.visit_all(callback, seen)
  File "F:\Desktop\Ren'py\renpy-7.1.0-sdk\renpy\display\screen.py", line 424, in visit_all
    callback(self)
  File "F:\Desktop\Ren'py\renpy-7.1.0-sdk\renpy\display\core.py", line 3049, in <lambda>
    root_widget.visit_all(lambda i : i.per_interact())
  File "F:\Desktop\Ren'py\renpy-7.1.0-sdk\renpy\display\screen.py", line 434, in per_interact
    self.update()
  File "F:\Desktop\Ren'py\renpy-7.1.0-sdk\renpy\display\screen.py", line 619, in update
    self.screen.function(**self.scope)
  File "game/encyclopaedia_screens.rpy", line 90, in execute
    screen encyclopaedia_list(enc):
  File "game/encyclopaedia_screens.rpy", line 90, in execute
    screen encyclopaedia_list(enc):
  File "game/encyclopaedia_screens.rpy", line 94, in execute
    window:
  File "game/encyclopaedia_screens.rpy", line 97, in execute
    vbox:
  File "game/encyclopaedia_screens.rpy", line 106, in execute
    frame:
  File "game/encyclopaedia_screens.rpy", line 110, in execute
    hbox:
  File "game/encyclopaedia_screens.rpy", line 113, in execute
    text "{} Complete".format(enc.labels.percentage_unlocked)
  File "<screen language>", line 113, in <module>
  File "game/enc.rpy", line 1071, in percentage_unlocked
    percentage_unlocked = int(self.encyclopaedia.percentage_unlocked)
  File "game/enc.rpy", line 719, in percentage_unlocked
    'Cannot calculate percentage unlocked of empty Encyclopaedia'
ZeroDivisionError: Cannot calculate percentage unlocked of empty Encyclopaedia

Windows-8-6.2.9200
Ren'Py 7.1.0.882
Encyclopedia 1.0
Tue Sep 11 22:21:15 2018

Human Bolt Diary
Regular
Posts: 97
Joined: Fri Oct 11, 2013 12:46 am
Contact:

Re: Encyclopaedia / Bestiary Framework

#48 Post by Human Bolt Diary » Wed Sep 12, 2018 7:10 am

You're creating the encyclopaedia twice. Once in an init block, once in a python block. If the code in the python block isn't inside a label, it won't be run. The entry is inside the python block, and so isn't run either. Thus the encyclopaedia is empty.

User avatar
AERenoir
Veteran
Posts: 300
Joined: Fri May 27, 2011 8:23 pm
Contact:

Re: Encyclopaedia / Bestiary Framework

#49 Post by AERenoir » Wed Sep 12, 2018 9:18 am

Oh, I see! I fixed it, thanks.

ETA: What if I want to add the entries one by one? Do I use "locked = True" or do I add the entry one by one in the script

User avatar
bonnie_641
Regular
Posts: 56
Joined: Sat Jan 13, 2018 10:57 pm
Projects: Código C.O.C.I.N.A.
Deviantart: rubymoonlily
Contact:

Re: Encyclopaedia / Bestiary Framework

#50 Post by bonnie_641 » Wed Oct 10, 2018 10:27 pm

I gave a second chance to version 2, but I do not understand anything. Between global and local variables, they confuse me a lot (I have little experience in programming, but it is not enough to understand the documentation). It is easier for me to learn with practical examples.
I appreciate your help, really :D :D , but I think I'll continue with version 1.5 :oops:

I know it's too much to ask for an example (since you gave yourself some time to share this tutorial and that time is valuable), but do not worry. Maybe in the previous version I have more luck to follow each instruction.

User avatar
isak grozny
Regular
Posts: 44
Joined: Mon Apr 11, 2016 10:17 am
Projects: The Bitter Drop [Modern Fantasy][Gay Romance][BxB]
itch: grrozny
Location: Edinburgh, UK
Contact:

Re: Encyclopaedia / Bestiary Framework

#51 Post by isak grozny » Wed Oct 24, 2018 12:24 am

Is there any way to integrate this with RenPy's built-in hyperlink protocols? I'm trying to achieve the following:
  • display a hyperlink using {a=protocol:foo}, like if "foo" was a menu, i'd do: {a=showmenu:foo}
  • have the hyperlink handler open the relevant encyclopaedia entry
I tried making a hyperlink protocol that would run enc.SetEntry(foo), but that didn't work. Is there something I'm missing?

Human Bolt Diary
Regular
Posts: 97
Joined: Fri Oct 11, 2013 12:46 am
Contact:

Re: Encyclopaedia / Bestiary Framework

#52 Post by Human Bolt Diary » Fri Oct 26, 2018 3:50 pm

Code: Select all

define config.hyperlink_handlers = {
    "set_entry": set_enc_entry_from_text_anchor,
}

init -1500 python:
    def set_enc_entry_from_text_anchor(value):
        p = value.split('->')
        enc = getattr(store, p[0])
        entry = getattr(store, p[1])
        
        enc.SetEntry(entry)()

init python:

    my_enc = Encyclopaedia()
    
    entry_one = EncEntry(
        parent=my_enc,
        name="First Entry",
        text=["Lorem ipsum"],
    )

label start:

    "blah blah {a=set_entry:my_enc->entry_one} blah blah {/a} blah blah"

I'll release an update soonish with this code built into the framework.
isak grozny wrote:
Wed Oct 24, 2018 12:24 am
Is there any way to integrate this with RenPy's built-in hyperlink protocols? I'm trying to achieve the following:
  • display a hyperlink using {a=protocol:foo}, like if "foo" was a menu, i'd do: {a=showmenu:foo}
  • have the hyperlink handler open the relevant encyclopaedia entry
I tried making a hyperlink protocol that would run enc.SetEntry(foo), but that didn't work. Is there something I'm missing?

User avatar
isak grozny
Regular
Posts: 44
Joined: Mon Apr 11, 2016 10:17 am
Projects: The Bitter Drop [Modern Fantasy][Gay Romance][BxB]
itch: grrozny
Location: Edinburgh, UK
Contact:

Re: Encyclopaedia / Bestiary Framework

#53 Post by isak grozny » Sat Oct 27, 2018 4:03 pm

Excellent, thank you!

User avatar
bonnie_641
Regular
Posts: 56
Joined: Sat Jan 13, 2018 10:57 pm
Projects: Código C.O.C.I.N.A.
Deviantart: rubymoonlily
Contact:

Re: Encyclopaedia / Bestiary Framework

#54 Post by bonnie_641 » Tue Oct 30, 2018 2:55 pm

Human Bolt Diary wrote:
Fri Oct 26, 2018 3:50 pm

Code: Select all

define config.hyperlink_handlers = {
    "set_entry": set_enc_entry_from_text_anchor,
}

init -1500 python:
    def set_enc_entry_from_text_anchor(value):
        p = value.split('->')
        enc = getattr(store, p[0])
        entry = getattr(store, p[1])
        
        enc.SetEntry(entry)()

init python:

    my_enc = Encyclopaedia()
    
    entry_one = EncEntry(
        parent=my_enc,
        name="First Entry",
        text=["Lorem ipsum"],
    )

label start:

    "blah blah {a=set_entry:my_enc->entry_one} blah blah {/a} blah blah"

With hyperlink it is easier to implement the content to the encyclopedia.
I will try this method. Thank you :D

User avatar
bonnie_641
Regular
Posts: 56
Joined: Sat Jan 13, 2018 10:57 pm
Projects: Código C.O.C.I.N.A.
Deviantart: rubymoonlily
Contact:

Re: Encyclopaedia / Bestiary Framework

#55 Post by bonnie_641 » Tue Nov 06, 2018 1:19 pm

It works with hyperlinks !!! (in encyclopaedia 2.1 framework)

Edit: It was my mistake to edit the interface of the encyclopedia :oops: :oops: :oops:
Last edited by bonnie_641 on Thu Nov 08, 2018 8:37 pm, edited 1 time in total.

User avatar
bonnie_641
Regular
Posts: 56
Joined: Sat Jan 13, 2018 10:57 pm
Projects: Código C.O.C.I.N.A.
Deviantart: rubymoonlily
Contact:

Re: Encyclopaedia / Bestiary Framework

#56 Post by bonnie_641 » Thu Nov 08, 2018 8:34 pm

A question:
How can I delete persistent data at the end of the game?

I tried with $ persistent._clear (progress = True), $ renpy.full_restart, $ renpy.reload_script but nothing happens.
I put all the Boolean variables to 'False', (ex. entry_two.viewed_persistent=False) but the percentage of the game is still 100% :oops:


Edit: I'll erase the percentage variable ... I think it's the fastest way.
------------------------
Last question:
Is it possible to put the hyperlink to an imagebutton?
In advance, thank you very much :D

Edit: Never mind. I will add sub entries to avoid creating the imagebuttons (although I'm curious anyway) :lol:


Code: Select all

define config.hyperlink_handlers = {
    "set_entry": set_enc_entry_from_text_anchor,
}

init -1500 python:
    def set_enc_entry_from_text_anchor(value):
        p = value.split('->')
        enc = getattr(store, p[0])
        entry = getattr(store, p[1])
        
        enc.SetEntry(entry)()


init python:
    #------------------------------------------
    # create a parent called 'postres' (as an object that belongs to Encyclopaedia )
    #-------------------------------------------
    postres = Encyclopaedia()
    
    #--------------------------- 
    # First page is dedicated to the parent of the entrance 
    #---------------------------
    morocha = EncEntry(
        parent=postres,
        name="morocha",
        image="morocha_image.png",
        text=["Test Text"],
    )

    #---------------------------------
    # Second page is dedicated to the descendant of the entrance 
    #---------------------------------
    morocha_1 = EncEntry(
        parent=morocha,
        name="A Sub-Page",
        image="morocha_1_image.png",
        text=["Test Text"],
    )
    
    #-------------------------------
    # to add more sub entries, create more 'children' with the same 'parent'
    #-------------------------------

    morocha_2 = EncEntry(
        parent=morocha,
        name="Sub-Page 2",
        image="morocha_2_image.png",
        text=["Test Text"],
    )

I know that 'morocha' is not a 'postre' (sweet), but I put a name at random to give a simple example (and avoid calling unnecessary hyperlinks)

User avatar
isak grozny
Regular
Posts: 44
Joined: Mon Apr 11, 2016 10:17 am
Projects: The Bitter Drop [Modern Fantasy][Gay Romance][BxB]
itch: grrozny
Location: Edinburgh, UK
Contact:

Re: Encyclopaedia / Bestiary Framework

#57 Post by isak grozny » Thu Dec 13, 2018 10:51 am

Incidentally, I implemented natural sorting in this framework–-the biggest thing is ignoring the/a/an at the start of a string, so e.g. "The Beatles" subject would be sorted as if it starts with B, not T. Shall I do a pull request on github or something similar?

Human Bolt Diary
Regular
Posts: 97
Joined: Fri Oct 11, 2013 12:46 am
Contact:

Re: Encyclopaedia / Bestiary Framework

#58 Post by Human Bolt Diary » Sun Dec 16, 2018 4:42 pm

isak grozny wrote:
Thu Dec 13, 2018 10:51 am
Incidentally, I implemented natural sorting in this framework–-the biggest thing is ignoring the/a/an at the start of a string, so e.g. "The Beatles" subject would be sorted as if it starts with B, not T. Shall I do a pull request on github or something similar?
PRs are welcome. Just make sure you haven't broken the linter or the tests, or decreased the code coverage.

User avatar
AERenoir
Veteran
Posts: 300
Joined: Fri May 27, 2011 8:23 pm
Contact:

Re: Encyclopaedia / Bestiary Framework

#59 Post by AERenoir » Wed Dec 26, 2018 5:51 am

Hi, I have a few questions

1) Can I use the hyperlink to jump from one entry to another? Like for example "George Washington is the President of the USA", and the the "USA" is a hyperlink to another entry about USA.

2) Can the entry buttons in the index show more than one line? For example, I want the button to look like a dictionary entry like this, so it has multiple lines:

Image

Can I just use the paragraph text tags?

3) Trying to understand how the screens work here... I'm not sure what the None does in this part, where I click the "close entry" button:

Code: Select all

[enc.ResetSubPage(), Show("encyclopaedia_list", None, enc)]
Can I somehow modify it so that instead of having to go back to index, I can return directly back into the game (the encyclopaedia is accessible in-game)

Thanks

Human Bolt Diary
Regular
Posts: 97
Joined: Fri Oct 11, 2013 12:46 am
Contact:

Re: Encyclopaedia / Bestiary Framework

#60 Post by Human Bolt Diary » Wed Dec 26, 2018 4:17 pm

AERenoir wrote:
Wed Dec 26, 2018 5:51 am
Hi, I have a few questions

1) Can I use the hyperlink to jump from one entry to another? Like for example "George Washington is the President of the USA", and the the "USA" is a hyperlink to another entry about USA.

2) Can the entry buttons in the index show more than one line? For example, I want the button to look like a dictionary entry like this, so it has multiple lines:

Image

Can I just use the paragraph text tags?

3) Trying to understand how the screens work here... I'm not sure what the None does in this part, where I click the "close entry" button:

Code: Select all

[enc.ResetSubPage(), Show("encyclopaedia_list", None, enc)]
Can I somehow modify it so that instead of having to go back to index, I can return directly back into the game (the encyclopaedia is accessible in-game)

Thanks
1) If it's a button, you can use encyclopaedia.SetEntry() https://renpy-encyclopaedia.readthedocs ... l#setentry
If it's text, look a few posts back for the code snippet about adding hyperlinks to encyclopaedia entries.

2) They're just normal Ren'Py buttons. The actions are what bind them to do things with an Encyclopaedia. If you can do it with a button, then it's possible.

3) The Show action is part of Ren'Py's API https://www.renpy.org/doc/html/screen_actions.html#Show

The encyclopaedia list and entry screens are just normal screens. If you want to close both at the same time, you can do something like:

Code: Select all

textbutton "Return"  action [enc.Sort(sorting_mode=enc.default_sorting_mode),
                                                     Hide("encyclopaedia_list"),
                                                     Hide("encyclopaedia_entry"),
                                                     enc.ResetSubPage(),
                                                     Return()]

Post Reply

Who is online

Users browsing this forum: No registered users