[CODE] Glossary Screen Implementation

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
bonnie_641
Regular
Posts: 133
Joined: Sat Jan 13, 2018 10:57 pm
Projects: Código C.O.C.I.N.A.
Deviantart: rubymoonlily
Contact:

Re: [CODE] Glossary Screen Implementation

#16 Post by bonnie_641 »

I leave this code for backup: Glossary modification in alphabetical order, unlockable and can reverse the order (RLinZ code modification).

EDIT:
I add pronunciation of words (thanks to enaielei): viewtopic.php?f=8&t=65672&p=556534#p556522

screen.rpy

Code: Select all

init python:
    config.hyperlink_handlers["play"] = renpy.play  # Sound is linked to speech by hyperlink handlers.

screen glossary():
    text "Glossary" size 40 xalign 0.5 ypos 20
    hbox spacing 200:
        viewport:
            xpos 50 ypos 100 xsize 300 ysize 500
            child_size (None, 4000)
            scrollbars "vertical"
            spacing 5
            draggable True
            mousewheel True
            arrowkeys True
            add "#000c"
            vbox spacing 20:
                #for word in sorted(persistent.palabra): # works only persistent words with nothing special
                #for word in sorted(persistent.palabra, reverse=True) : # changes the order of presentation
                for word in sorted(persistent.palabra, key=str.lower) :  # order the list  :D 
                    textbutton word:
                        action SetVariable("display_desc", word)
        vbox ypos 100 xsize 650 ysize 500 box_wrap True:
            text glossary_dict.get(display_desc, "")

init -1 python:

    display_desc = ""
    
    ######################################################
    # Choose only one option for the glossary word to read:   ##
    ######################################################
    # Option 1: Pronunciation with robotic effect                   ##
    #-----------------------------------------------------------------------##
    def play(tag, argument, contents):                                   ##
        renpy.play(argument)                                                    ##
        return contents                                                            ##
                                                                                             ##
    config.custom_text_tags["play"] = play                             ##
    #----------------------------------------------------------------------##
    #####################################################
    # Option 2: Pronunciation normal                                    ##
    #---------------------------------------------------------------------##
    config.hyperlink_handlers["play"] = renpy.play                ##
    #---------------------------------------------------------------------##
    ####################################################

    #add words to the dictionary
    glossary_dict = \
        {
        ##################################################################
        # If you chose the first option:
        #'Cook': '{play=audio/cook.mp3}DEFINITION COOK OR WHATEVER{/play}',
        #If you chose the SECOND option:
        #'Cook': '{a=play:cook.mp3}DEFINITION COOK OR WHATEVER{/a}',
        ##################################################################
        
        'Cut': '{play=audio/cut.mp3}DEFINITION CUT OR WHATEVER{/play}',
        'a':'{play=audio/a.mp3}DEFINITION A OR WHATEVER{/play}',
        'say':'{play=audio/say.mp3}DEFINITION SAY OR WHATEVER{/play}',
        
        }



script.rpy

Code: Select all

define persistent.palabra= set()

label start:

    show screen glossary
    "¿?"
    "¿Nothing?"
    hide screen glossary
    "Don't work?"
    "Maybe..."
    jump checking_words



label checking_words:

    "Let's see..."

    $ persistent.palabra.add('Cook')
    show screen glossary
    "Adding 'Cook'."

    #$ persistent.palabra.remove('Cook') ##: To remove the word "Cook" from the glossary
    "Yay!!!! ♥"

    hide screen glossary
    
    "If I add 'Cut'..."
    $ persistent.palabra.add('Cut')
    "..."
    show screen glossary
    "Oh! Adding 'Cut'."
    "¡¡¡¡¡AAAAHHHHHH!!!!! It's working!!!!!  :D"
    hide screen glossary
    
    "If I add 'a'..."
    $ persistent.palabra.add('a')
    "..."
    show screen glossary
    "It's working.... ♥"
    "The end?"
    return


Thank you RLinZ and enaielei for help me :D :wink:
I speak and write in Spanish. I use an English-Spanish translator to express myself in this forum. If I make any mistakes, please forgive me.
I try my best to give an answer according to your question. :wink:

User avatar
Andredron
Miko-Class Veteran
Posts: 688
Joined: Thu Dec 28, 2017 2:37 pm
Location: Russia
Contact:

Re: [CODE] Glossary Screen Implementation

#17 Post by Andredron »

search box function with imagebuttons
viewtopic.php?f=8&t=66032

Post Reply

Who is online

Users browsing this forum: No registered users