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
User avatar
noeinan
Eileen-Class Veteran
Posts: 1080
Joined: Sun Apr 04, 2010 10:10 pm
Projects: Ren'Py QuickStart, Crimson Rue
Organization: Statistically Unlikely Games
Deviantart: daikiraikimi
Github: daikiraikimi
Location: Washington State, USA
Contact:

Re: Encyclopaedia / Bestiary Framework

#16 Post by noeinan » Sun Jan 29, 2017 9:17 pm

LabaroDD wrote:Here is the way to disable sorting?
Maybe removing the sorting buttons?
Image

Image
Image

LabaroDD
Regular
Posts: 34
Joined: Thu Apr 14, 2016 7:47 am
Contact:

Re: Encyclopaedia / Bestiary Framework

#17 Post by LabaroDD » Sun Jan 29, 2017 9:47 pm

daikiraikimi wrote:
LabaroDD wrote:Here is the way to disable sorting?
Maybe removing the sorting buttons?
It wasn't enough just remove it... So I commented up parts of "SortingMode" in encyclopaedia.rpy and script.rpy and left this part (in script.rpy either):

Code: Select all

screen encyclopaedia_list:
    tag menu
    use encyclopaedia_navigation
    vbox:
        style_group "mm_root"  

        viewport:
            scrollbars "vertical"
            mousewheel True
            draggable True

            vbox: 
#                text encyclopaedia.sortingMode xalign 0.5 #Flavour text to display the current sorting mode.

                python:
                    for x in range(encyclopaedia.entry_list_size):
                            generateEntryButton(x,encyclopaedia)

Another one, more important question: is it anyhow possible to separate entries by themes on different screens, like on different pages?
For example:
Characters ► list of the characters (entries' subject marked as "Characters")
Items ► list of the items (entries' subject marked as "Items")
etc

I really can't get it.

User avatar
noeinan
Eileen-Class Veteran
Posts: 1080
Joined: Sun Apr 04, 2010 10:10 pm
Projects: Ren'Py QuickStart, Crimson Rue
Organization: Statistically Unlikely Games
Deviantart: daikiraikimi
Github: daikiraikimi
Location: Washington State, USA
Contact:

Re: Encyclopaedia / Bestiary Framework

#18 Post by noeinan » Mon Jan 30, 2017 3:38 pm

Hm, again this is just my best guess, but here is where I would start. First, looking at the main entries, en1/2/3/etc. are stored in "encyclopaedia" while sub-entries are stored in en1/2/3/etc. My thoughts are you could make encyclopedia1, encyclopedia2, etc.

Code: Select all

    # Define an encyclopaedia object.
    encyclopaedia1 = Encyclopaedia(
        sorting_mode = Encyclopaedia.SORT_NUMBER,
        show_locked_buttons=True,
        show_locked_entry=True,
        entry_screen="encyclopaedia_entry"

    # Define an encyclopaedia object.
    encyclopaedia2 = Encyclopaedia(
        sorting_mode = Encyclopaedia.SORT_NUMBER,
        show_locked_buttons=True,
        show_locked_entry=True,
        entry_screen="encyclopaedia_entry"

Code: Select all

    en1 = EncEntry(
        encyclopaedia1,
        1,
        "First Character",
        [
            "Character Name. Lorem ipsum dolor sit amet, consectetur adipiscing elit. ",
            "Vivamus in nisl magna. Fusce nec bibendum magna, sed venenatis erat. ",
            "Sed non dapibus augue, quis hendrerit diam. ",
            "Quisque bibendum turpis vitae orci iaculis volutpat. ",
            "Proin venenatis, nunc quis tempus convallis, lectus eros ultrices sem, eu condimentum tellus nisi sed magna. ",
            "Curabitur laoreet posuere orci eu eleifend. ",
            "Vivamus sed dui dignissim, egestas lorem eu, lobortis arcu. ",
            "Duis venenatis sem eu ipsum condimentum adipiscing. ",
            "Ut vel augue ut velit bibendum varius pharetra nec ligula. ",
            "Duis eu sollicitudin mauris. ",
            "Praesent vestibulum ligula vel ligula condimentum dignissim. ",
            "Ut risus velit, laoreet sed pellentesque sed, suscipit in massa. ",
            "Etiam posuere fringilla purus.",
        ],
        "Love Interests",
        viewed=persistent.new_status["new_01"],
        locked=False,
        image=en1_image,
    )
Seems to me like you would basically be creating a three tiered encyclopedia instead of a 2 tiered one. So, you would have multiple encyclopedias, each with their own entries and sub-entries. You would need to flat out copy the encyclopedia list screen and make a duplicate. Then each screen would need to have buttons leading to each other (like "tabs" or whichever, saying "characters", "Items", etc.)

Code: Select all

screen encyclopaedia_list(enc):
    tag menu
    modal True
^Right now the list of all base entries takes enc, or individual entries. Maybe you can tweak this so it will instead list encyclopedias? Alternatively, you could make your own, new screen where each button points to a different encyclopedia list (character_list, item_list, etc.) corresponding to the various types you want.
Image

Image
Image

LabaroDD
Regular
Posts: 34
Joined: Thu Apr 14, 2016 7:47 am
Contact:

Re: Encyclopaedia / Bestiary Framework

#19 Post by LabaroDD » Mon Jan 30, 2017 5:56 pm

Thanks for advice, I'll try to do it right now!
...Well, I have a first problem here:

Code: Select all

I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/enc_data.rpy", line 9: is not terminated with a newline. (Check strings and parenthesis.)
        encyclopaedia1 = Encyclopaedia(

Ren'Py Version: Ren'Py 6.99.11.1749
Where exactly I should define an encyclopaedia1, etc?

User avatar
noeinan
Eileen-Class Veteran
Posts: 1080
Joined: Sun Apr 04, 2010 10:10 pm
Projects: Ren'Py QuickStart, Crimson Rue
Organization: Statistically Unlikely Games
Deviantart: daikiraikimi
Github: daikiraikimi
Location: Washington State, USA
Contact:

Re: Encyclopaedia / Bestiary Framework

#20 Post by noeinan » Mon Jan 30, 2017 6:16 pm

LabaroDD wrote:Thanks for advice, I'll try to do it right now!
...Well, I have a first problem here:

Code: Select all

I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/enc_data.rpy", line 9: is not terminated with a newline. (Check strings and parenthesis.)
        encyclopaedia1 = Encyclopaedia(

Ren'Py Version: Ren'Py 6.99.11.1749
Where exactly I should define an encyclopaedia1, etc?
So, in general you will probably have to be really careful about making sure you replace everywhere in the script that uses "encyclopaedia" with "encyclopaedia1" (and that you duplicate those sections for the second encyclopaedia, too.) Regarding your error, that looks to me like it has nothing to do with adding the one and instead is a problem with spaces or parenthesis.

On my screen, this is what that code looks like:

Code: Select all

    # Define an encyclopaedia object.
    encyclopaedia = Encyclopaedia(
        sorting_mode = Encyclopaedia.SORT_NUMBER,
        show_locked_buttons=True,
        show_locked_entry=True,
        entry_screen="encyclopaedia_entry"
    )
Maybe check to make sure you didn't bump anything with spaces, or accidentally delete the ending parentheses, as everything has to be perfect or it will break.
Image

Image
Image

LabaroDD
Regular
Posts: 34
Joined: Thu Apr 14, 2016 7:47 am
Contact:

Re: Encyclopaedia / Bestiary Framework

#21 Post by LabaroDD » Tue Jan 31, 2017 5:16 pm

Thank you, daikiraikimi, it works!

The last one question and I'll finally leave you: could you help me with sub-entry text? After unlocking sub-entries appears in the next pages by default, but I want them appearing in the end of main entry's text block, without any pages. Like this:
"Main entry, blablabla"
+
"Sub-entry, blablabla"

I have boxes with scrolling, and sub-entries in pages looks pretty strange.

User avatar
noeinan
Eileen-Class Veteran
Posts: 1080
Joined: Sun Apr 04, 2010 10:10 pm
Projects: Ren'Py QuickStart, Crimson Rue
Organization: Statistically Unlikely Games
Deviantart: daikiraikimi
Github: daikiraikimi
Location: Washington State, USA
Contact:

Re: Encyclopaedia / Bestiary Framework

#22 Post by noeinan » Tue Jan 31, 2017 6:35 pm

LabaroDD wrote:Thank you, daikiraikimi, it works!

The last one question and I'll finally leave you: could you help me with sub-entry text? After unlocking sub-entries appears in the next pages by default, but I want them appearing in the end of main entry's text block, without any pages. Like this:
"Main entry, blablabla"
+
"Sub-entry, blablabla"

I have boxes with scrolling, and sub-entries in pages looks pretty strange.
No problem at all, I'm glad I could help. So, regarding what you're describing, it seems like you want the ability to add more text to main entries after they are unlocked in gameplay? I think there is a better way of doing this that doesn't deal with sub-entries, actually. Instead it just adds text onto the end of the main entry block.

I have not personally done this myself, so I won't be able to give a definite answer until I try it out. However, Human Bolt Diary made a post about this earlier in the thread, maybe that will help you out: viewtopic.php?f=51&t=25204#p368351

I think a way to do this could be storing entry text as a list instead of a variable, and then appending (adding) the new text to the end of the list when you reach certain points in the game. That would look something like this:

Code: Select all

    # Herb Identification vol. 1
    en1 = EncEntry(
        encyclopaedia,
        1,
        "Herb Identification vol. 1",
        [
            "Thistle. Lorem ipsum dolor sit amet, consectetur adipiscing elit. ",
            "Vivamus in nisl magna. Fusce nec bibendum magna, sed venenatis erat. ",
            "Sed non dapibus augue, quis hendrerit diam. ",
            "Quisque bibendum turpis vitae orci iaculis volutpat. ",
            "Proin venenatis, nunc quis tempus convallis, lectus eros ultrices sem, eu condimentum tellus nisi sed magna. ",
            "Curabitur laoreet posuere orci eu eleifend. ",
            "Vivamus sed dui dignissim, egestas lorem eu, lobortis arcu. ",
            "Duis venenatis sem eu ipsum condimentum adipiscing. ",
            "Ut vel augue ut velit bibendum varius pharetra nec ligula. ",
            "Duis eu sollicitudin mauris. ",
            "Praesent vestibulum ligula vel ligula condimentum dignissim. ",
            "Ut risus velit, laoreet sed pellentesque sed, suscipit in massa. ",
            "Etiam posuere fringilla purus.",
        ],
        "Herb Identification",
        viewed=persistent.new_status["new_01"],
        locked=False,
        image=en1_image,
    )
I think there might be other parts of the code that would need to be changed, too-- if this is something you're interested in then I would recommend sending Human Bolt Diary a pm.
Image

Image
Image

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

Re: Encyclopaedia / Bestiary Framework

#23 Post by Human Bolt Diary » Wed Feb 01, 2017 12:49 am

LabaroDD wrote:Thank you, daikiraikimi, it works!

The last one question and I'll finally leave you: could you help me with sub-entry text? After unlocking sub-entries appears in the next pages by default, but I want them appearing in the end of main entry's text block, without any pages. Like this:
"Main entry, blablabla"
+
"Sub-entry, blablabla"

I have boxes with scrolling, and sub-entries in pages looks pretty strange.
You can swap out the entire text in an entry by doing:

Code: Select all

your_entry.text = ["An entirely new set of text for the entry."]
You should be able to append new text with:

Code: Select all

your_entry._text.append("A new line of text.")
But this won't flip the viewed flag for the entry. You'll need to do that manually as well.

You could also rewrite the screen that shows an entry to show all the text from every sub-entry.

User avatar
noeinan
Eileen-Class Veteran
Posts: 1080
Joined: Sun Apr 04, 2010 10:10 pm
Projects: Ren'Py QuickStart, Crimson Rue
Organization: Statistically Unlikely Games
Deviantart: daikiraikimi
Github: daikiraikimi
Location: Washington State, USA
Contact:

Re: Encyclopaedia / Bestiary Framework

#24 Post by noeinan » Wed Feb 01, 2017 2:57 am

I actually have a question of my own! I'm using this code in conjunction with sanguaro's inventory/craft/store code (link: viewtopic.php?f=51&t=25579&start=30 )

I am attempting to make an item that unlocks an entry in the encylcopedia. The idea is that you get a book, and when you click it you "read" it and gain access to the information inside. Since each entry is a "book" all the sub-entries are pages, and they all get unlocked at once instead of one at a time. I added the following code:

In EncEntry.py

Code: Select all

def unlock_entry(self):

    self.locked = False
    self.viewed = False
    
    if entry.has_sub_entry:
        for subent_data in entry.sub_entry_list:
        subent_data[1].locked = False
        self.add_entry(subent_data[1])
        self.viewed = False
In action.py:

Code: Select all

class UnlockEncEntry(EncyclopaediaAction):
    def __init__(self, entry):
        self.entry = entry

    def __call__(self):
        entry.unlock_entry()
The inventory code takes in these variables:

Code: Select all

    class Item(store.object):
        def __init__(self, name, desc, icon=False, value=0, act=Show("inventory_popup", message="Nothing happened!"), type="item", recipe=False):
            global cookbook
            self.name = name
            self.desc = desc
            self.icon = icon
            self.value = value               
            self.act = act # screen action
            self.type = type # type of item
            self.recipe = recipe # nested list of [ingredient, qty]   
            
            if recipe:
                cookbook.append(self)
                cookbook.sort(key=lambda i: i.name) #alpha order
And I need to define items *after* the start label like so:

Code: Select all

$ book = Item("Herb Identification Guide", "A book of herbs", "inv/book.png", 5000, act=UnlockEncEntry(en1))
The problem I am running into is that when I run my game, as soon as inventory items are defined it crashes, telling me that "UnlockEncEntry" is not defined. As far as I understand, act should take anything that goes with action-- and EncyclopaediaAction is a subclass of Action, so it should take.

My best guess is that the code in the encyclopaedia folder is not being run until after the start label. It's in a .py file as opposed to a .rpy file, so I'm not 100% sure how to control when it gets read. Normally, I would put it in an init python block. The classes for my items and inventory are defined in one. Since it's a .py file, seems to me that it's already in a python (no block needed) but is there a way to make sure it is read before the game start, similar to init?
Image

Image
Image

User avatar
noeinan
Eileen-Class Veteran
Posts: 1080
Joined: Sun Apr 04, 2010 10:10 pm
Projects: Ren'Py QuickStart, Crimson Rue
Organization: Statistically Unlikely Games
Deviantart: daikiraikimi
Github: daikiraikimi
Location: Washington State, USA
Contact:

Re: Encyclopaedia / Bestiary Framework

#25 Post by noeinan » Wed Feb 01, 2017 3:25 pm

My friend told me I might need to import EncyclopaediaActions in the code where I define my items and I got it working! Here is the code for anyone else who wants to implement something like this! :D I'm using saguaro's inventory/crafting/store code which you can find here: viewtopic.php?f=51&t=25579

So, first I had to change the name of the folder that stores the encyclopaedia code. If I didn't, then the fact that the module and the actual encyclopaedia had the same name was giving me errors. I changed it to enc_code, and changed everywhere that the module was imported to reflect that.

In EncEntry (enc_code.encentry) I added this function:

Code: Select all

    def unlock_entry(self):
        #Changes the locked status of an entry and all sub-entries
        self.locked = False
        self.viewed = False
        
        if self.has_sub_entry:
            for subent_data in self.sub_entry_list:
                subent_data[1].locked = False
                self.add_entry(subent_data[1])
                self.viewed = False
Then, in enc_code.actions I changed the import to reflect the module name change:

Code: Select all

import enc_code.encentry
Then I added this new action, which I needed so that I could use it as an item action:

Code: Select all

class UnlockEncEntry(EncyclopaediaAction):
    #Calls EncEntry.unlock_entry, can be assigned to a button
    def __init__(self, entry):
        self.entry = entry

    def __call__(self):
        enc_code.encentry.EncEntry.unlock_entry(self.entry)
In the base item code, all items are defined after the start label. I made item definition and inventory definition labels so that I could jump to them and save space in the start label. In the item definition label, I imported EncEntry and EncyclopaediaActions. I had to import the whole thing instead of "from enc_code.actions import EncEntryUnlock" or else I got an error.

Code: Select all

label define_items:
    $ import enc_code.encentry
    $ import enc_code.actions 
    "Encyclopaedia Actions have been imported."
    
    ######### DEFINE ITEM OBJECTS ##########
    ### The format is name, description, icon image (if applicable), value (if applicable, selling/buying value), action (screen language action to be performed when icon is clicked on inventory screen), and recipe (if craftable).
Then I made my items!

Code: Select all

#Books
    #This is currently broken. It says UnlockEncEntry is not defined. 
    #Need to investigate when the action code for encyclopedia runs. 
    
    $ herbID1 = Item("Herb Identification vol. 1", "A book of herbs", "inv/book.png", 5000, act=enc_code.actions.UnlockEncEntry(en1))
    $ herbID2 = Item("Herb Identification vol. 2", "A book of herbs", "inv/book.png", 5000, act=enc_code.actions.UnlockEncEntry(en2))
    $ herbID3 = Item("Herb Identification vol. 3", "A book of herbs", "inv/book.png", 5000, act=enc_code.actions.UnlockEncEntry(en3))
I will probably polish this up but this code is functional! (I eventually want to make it so that when you click on the item it gives you a little popup saying "you read the book" and also that reading a book consumes time, but I will figure that out later. For now, this is working and I wanted to share it with folks in case anyone else wanted to do something similar at some point. :3 )
Image

Image
Image

LabaroDD
Regular
Posts: 34
Joined: Thu Apr 14, 2016 7:47 am
Contact:

Re: Encyclopaedia / Bestiary Framework

#26 Post by LabaroDD » Fri Feb 03, 2017 1:20 pm

Thank you, Human Bolt Diary!

Oh, one more problem... I got an error when I came back from the Encyclopaedia to game. It pops up when I click on "Return" button.

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "renpy/common/00gamemenu.rpy", line 173, in script
    $ ui.interact()
  File "renpy/common/00gamemenu.rpy", line 173, in <module>
    $ ui.interact()
  File "game/encyclopaedia.rpy", line 298, in __call__
    self.enc_dict[self.tag_string + str(x)] = self.enc.all_entries[x][1].status
TypeError: 'NoneType' object does not support item assignment

LabaroDD
Regular
Posts: 34
Joined: Thu Apr 14, 2016 7:47 am
Contact:

Re: Encyclopaedia / Bestiary Framework

#27 Post by LabaroDD » Fri Feb 03, 2017 2:59 pm

I found the answer myself. I used a line of code right below the label start:

Code: Select all

$ persistent._clear(progress=True)
so it conflicted to this:

Code: Select all

self.enc_dict[self.tag_string + str(x)] = self.enc.all_entries[x][1].status
I simply deleted the first line.

User avatar
gas
Veteran
Posts: 450
Joined: Mon Jan 26, 2009 7:21 pm
Contact:

Re: Encyclopaedia / Bestiary Framework

#28 Post by gas » Sun Feb 05, 2017 12:50 am

For those that want to add more than one encyclopaedia, shown on different screens... (done today, streamlined process).

STEP A
Create the data of the second ency, after an init, like that.
I called this extra dictionary 'encyguide'.

Code: Select all

init:
    whatsabout = "Yes"
    kimassen= "Hopefully"
    encyguide = Encyclopaedia(showLockedButtons=True, showLockedEntry=False) 
    encyguide.setPersistentStatus(entries_total=2, master_key="new", name="new")
    encyguide.addSubjects("Tutorial")
    gd1 = EncEntry(1,"Medicine",whatabout, "Tutorial", status=persistent.new_dict["new_00"], locked=False)
    gd2 = EncEntry(2,"Voodoo",whatstime, "Tutorial", status=persistent.new_dict["new_01"],locked=False)
    encyguide.addEntries(gd1,gd2) 
Please notice that, CONTRARY TO COMMENT ON THE ORIGINAL SCRIPT, you had to set "new" as master_key and name here too, or an error will stop everything.

STEP B
Create a COPY of the full generateEntryButton(x,enc) function in an init -1 block. The same exact function, just changing the name.
In my game, I called it ExtragenerateEntryButton.
That's because there's a couple of hardcoded lines you need to change.
Scroll the new replicated function until you read something like:

Code: Select all

Show("encyclopaedia_entry")] )
And change it this way:

Code: Select all

Show("extra_encyclopaedia_entry")] )
'encyclopedia_entry" is the screen that show a single voice. If you don't change it, you'll got an error or strange behaviors. So change it as "extra_encyclopedia_entry" every time appear in your new renamed function. It appear more than once.

That's my result, with some style too.You can copy/paste it where you want.

Code: Select all

init -1 python:
 #Function that creates the buttons for each entry.
 #It makes one button, based on the value "x", associated to the given encyclopaedia "enc".
 #Used in a "for loop" on a screen to generate the correct buttons for every entry 
    def ExtragenerateEntryButton(x,enc):  
        ui.hbox()
        if enc.showLockedButtons:
            if enc.all_entries[x][1].locked == False: #If the entry is unlocked, make the button to go to it. If it's locked, make an inactive "???" button
                if enc.all_entries[x][1].status == None or enc.all_entries[x][1].status == False:
                    ui.textbutton ("{color=#ff0}New!{/color}", xsize=60, color="#f0f", size=16)
                else:
                    ui.null(width=60)
                ui.textbutton(enc.all_entries[x][1].name, clicked= [ enc.ChangeStatus(x), enc.SetEntry(x), Show("extra_encyclopaedia_entry")] )
                
          
            else: #If locked entries should be shown in the list, the "???" button should go to the entry. If not, it's an inactive button
                if enc.showLockedEntry:
                    ui.null(width=60)
                    ui.textbutton("{color=#666}???{/color}", clicked=[ enc.ChangeStatus(x), enc.SetEntry(x), Show("extra_encyclopaedia_entry")])
                else:
                    ui.null(width=60)
                    ui.textbutton("{color=#666}???{/color}")
    
        if enc.showLockedButtons == False: #Only showing unlocked entries in this case, no need for the "???" button
            ui.textbutton(enc.unlocked_entries[x][1].name, clicked= [ enc.ChangeStatus(x), enc.SetEntry(x), Show("extra_encyclopaedia_entry")] )
            if enc.unlocked_entries[x][1].status == None or enc.unlocked_entries[x][1].status == False:  
                ui.textbutton ("New!")
        ui.close()
STEP C
Now for the screen... paste this. Don't forget to add a menu voice in the navigation to reach "extra_encyclopaedia_list". Please notice where "encyguide", my new ency, is used:

Code: Select all

screen extra_encyclopaedia_list:
    tag menu
 
    use game_menu(_("Guides"), scroll="viewport"):

        vbox:
            spacing 10
            frame:
                style_prefix "guide"  
                xmargin 10
                yfill True
                xmaximum 400
                bottom_margin 10
   
                vbox: #viewport:
                    #scrollbars "vertical"
                    #mousewheel True
                    #draggable True
     
                    vbox: 
                        python:
                            for x in range(len(encyguide.subjects) ):
                                ui.text(encyguide.subjects[x])
                                for y in range(encyguide.entry_list_size):  
                                    if encyguide.getEntry(y).subject == encyguide.subjects[x]:
                                        ExtragenerateEntryButton(y,encyguide)   ### <-notice this!
                                ui.null(height=16)

  ######################
### ENC. single entry  ##################################################################
  # ================== #
  ######################
screen extra_encyclopaedia_entry():
    tag menu
    use game_menu(_("Guides"), scroll="viewport"):
        vbox:
            spacing 10
            frame:
                id "entry_nav"
                style_prefix "guidenavi"
                xfill True
                hbox:
                    xfill True
                    textbutton "Previous Entry" xalign .02 action encyguide.PreviousEntry() #Relative to the sorting mode
                    $page_indicator = encyguide.getEntryData()[1].getName() # Flavour text to indicate which page we're current on
                    text page_indicator size 36 color "#c00"
                    textbutton "Next Entry" xalign .98 action encyguide.NextEntry() #Relative to the sorting mode  
       
  
            hbox:
                $ddd = config.screen_width
                $dd = config.screen_width/2
                $pp = config.screen_height/2
                if encyguide.getEntryData()[1].hasImage: #If the entry or sub-entry has an image, add it to the screen   
                    frame:
                        xmargin 10
                        yfill True
                        xfill True

                        xmaximum dd
                        ymaximum pp  

                        $current_image = encyguide.getEntryData()[1].getImage()
                        add current_image crop (0,10,dd-30,pp-10)
   
                window:
                    id "entry_window"
                    xmargin 10
                    xfill True
                    yfill True
                    xalign 0.5
                    xmaximum ddd
                    ymaximum pp
                    background None
                     
                    vbox:
                        spacing 15
                        for item in encyguide.entry_text: #entry_text is a list of paragraphs from what whatever the current entry is
                            text item

            frame:
                style_group "mm_root"  
                xfill True
                yfill False
                xmargin 10
   
                hbox:
                    xfill True  
  
                    if encyguide.getEntryData()[1].hasSubEntry: #If there's a sub-entry, add Prev/Next Page buttons     
                        textbutton "Previous Page" xalign .02 action encyguide.PreviousPage()

                        text "Page %d / %d" % (encyguide.sub_current_position, encyguide.getEntryData()[1].pages) #Flavour text to indicate which sub-page is being viewed

                        textbutton "Next Page" xalign .98 action encyguide.NextPage()  
 
                    else:
                        text("")
        hbox:
            xfill True
            yalign .98
            textbutton "Close Entry" id "close_entry_button" xalign .5 clicked [encyguide.ResetSubPage(), Show("extra_encyclopaedia_list")] #<---notice this
That's all. With the same process you can add infinite numbers of different encys to your game (I've done one at title for setting lore, and one for game mechanics at game menu).
10 ? "RENPY"
20 GOTO 10

RUN

User avatar
noeinan
Eileen-Class Veteran
Posts: 1080
Joined: Sun Apr 04, 2010 10:10 pm
Projects: Ren'Py QuickStart, Crimson Rue
Organization: Statistically Unlikely Games
Deviantart: daikiraikimi
Github: daikiraikimi
Location: Washington State, USA
Contact:

Re: Encyclopaedia / Bestiary Framework

#29 Post by noeinan » Mon Feb 13, 2017 1:53 am

daikiraikimi wrote:My friend told me I might need to import EncyclopaediaActions in the code where I define my items and I got it working! Here is the code for anyone else who wants to implement something like this!

Just wanted to add a follow-up on this! So, I did eventually figure out how to make it so clicking an item gives you a popup saying "you read the book" or similar and I also made it consume one unit of time, and change picture that shows the time of day. For those interested:

Code: Select all

$ herbID1 = Item("Herb Identification vol. 1", "A book of herbs", "inv/book.png", 5000, act=[enc_code.actions.UnlockEncEntry(en1),Show("inventory_popup", message="New Herbs Unlocked"), SetVariable('time_cnt',time_cnt+1), Function(renpy.call, "time_img")])
Warning to peeps-- this uses the call function in a button, and according to my research this has the potential to break RenPy, ergo it must be used with caution. I found that if the button is pressed while the textbox is up it causes problems, but as long as RenPy is paused it seemed to work fine.

Second thing is, I discovered a bug in my code which unlocks entries. I haven't fixed it yet, but basically unlocking entries through a button seems to break how the code displays entries. Like, the button in the encyclopedia list will lock/unlock, but when you click it you get an error message.

Dunno if unlocking entries through other means changes other things, but I'm looking into it. Under the current code I made, if you click "next entry" it skips the newly unlocked entry all together, and if you click on the unlocked entry directly from the encyclopedia list you get an error message:

Code: Select all

  File "enc_code/actions.py", line 33, in __call__
ValueError: EncEntry: 02: Herb Identification vol. 2 is not in list
I know it worked before I made the entry unlockable via button, so basically I'm going to dig around in the code and figure out what's up. Will post back here with a solution when I find it.
Image

Image
Image

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

Re: Encyclopaedia / Bestiary Framework

#30 Post by Human Bolt Diary » Sat Nov 25, 2017 9:14 pm

In response to a lot of the difficulties people were having, I've been working on a version 2 of the Encyclopaedia Framework. I've kept most of the core concepts similar, but this is a hard break for quite a bit of the behaviour. Overall, it should be much more user-friendly and easier to customize.

The beta for v2 is available at:
https://github.com/jsfehler/renpy-encyc ... a/releases

and documentation at:
http://renpy-encyclopaedia.readthedocs. ... index.html

Getting v2 out of beta is going to take a lot more manual testing (I've tested it a lot, but I'm sure there's things I've missed.), more work on the documentation, and more unit tests.

Post Reply

Who is online

Users browsing this forum: No registered users