Lexicon Entries Overriding Each Other

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
BeepBoop
Newbie
Posts: 6
Joined: Wed Jul 26, 2023 1:26 pm
Contact:

Lexicon Entries Overriding Each Other

#1 Post by BeepBoop »

Hi! I'm using the lexicon code from this thread: viewtopic.php?p=508523#p508523 and I'm having an issue regarding the names of lexicon terms.

Basically, I've made a couple of lexicon entries with similar names, but one is prioritized over the other.

Here is the (example) code:

Code: Select all

# Tooltip variables

init python:

    lexicon = { # _('primary phrase'), _('optional synonyms') : """ description """,
      ( _('Visual Novel'), _('VN') )  : _("""
            A visual novel (bijuaru noberu) is an interactive game genre, 
            which originated in Japan in the early 1990s, featuring mostly 
            static graphics, most often using anime-style art or occasionally 
            live-action stills.
            As the name might suggest, they resemble mixed-media novels."""),
        (_('Visual Novel Writer') ) : _("""
            Someone who writes visual novels."""),
        ( _('Ren\'Py'), _('Renpy') ) : _("""
            The Ren'Py Visual Novel Engine is a free software engine which 
            facilitates the creation of visual novels, a form of 
            computer-mediated storytelling. Ren'Py is a portmanteau of ren'ai, 
            the Japanese word for 'romantic love' and Python, 
            the programming language that Ren'Py runs on. """),
    }

    def hyperlink_lexicon( str_to_test ):

        for keys in lexicon:
        
            if isinstance(keys, basestring):
                keys = [keys]
        
            for phrase in keys:

                # preceded by a space
                str_to_test = str_to_test.replace(
                    " {0}".format(phrase),
                    " {{a=lexicon:{phrase}}}{phrase}{{/a}}".format(
                        phrase = phrase ) )
                
                # followed by a space
                str_to_test = str_to_test.replace(
                    "{0} ".format(phrase),
                    "{{a=lexicon:{phrase}}}{phrase}{{/a}} ".format(
                        phrase = phrase ) )
        
        return str_to_test

    config.say_menu_text_filter = hyperlink_lexicon


    def hyperlink_styler(*args):

        return style.hyperlink_text

    def hyperlink_hovered(*args):
        
        if not args[0]:
            # Ren'Py 7+ recent nightly only, see below
            renpy.hide_screen("lexicon_popup")
            renpy.restart_interaction()
        
        elif args[0][:8] == "lexicon:":

            renpy.show_screen( "lexicon_popup", 
                args[0][8:], 
                renpy.get_mouse_pos() )
            
            renpy.restart_interaction()
        
        return


    def hyperlink_clicked(*args):

        if args[0] and args[0][:8] != 'lexicon:':

            # adapted from common/00defaults.rpy
            if args[0].startswith("http:") or args[0].startswith("https:"):
                try:
                    import webbrowser
                    webbrowser.open(args[0])
                except:
                    renpy.notify("Failed to open browser")

            elif args[0].startswith("jump:"):
                renpy.jump( args[0][5:] )

            else:
                renpy.call_in_new_context(args[0][args[0].index(':')+1:])

    
    style.default.hyperlink_functions = ( hyperlink_styler, hyperlink_clicked, hyperlink_hovered )


screen lexicon_popup(phrase=None, pos=(100,100)):

    if phrase:

        python:
            # get description
            d = [ lexicon[k] for k in lexicon if phrase in k ]
            description = d[0] if len(d) else "No description found."
            description = " ".join( [ k for k in description.split()
                if k not in [" ", "\t"] ] )
            
            # move the ypos up by a bit
            pos = ( pos[0], pos[1] - 25 )

            # reformat phrase
            p = [ k for k in lexicon if phrase in k ]
            primary_phrase = p[0][0] if len(p) else phrase
            if primary_phrase != phrase:
                phrase = "{0} ({1})".format(phrase, primary_phrase)

        frame:
            anchor (0.5, 1.0)
            pos pos
            xsize 340
            background Solid("#A9B")
            vbox:
                text "[phrase]" size 18
                text "[description]" size 14

Here is the result of that code:

Image

Image


I've tried restructuring the lexicon and reformatting entries, but nothing has worked. Best case scenario, nothing happens, worst case, my game crashes.

Any ideas? Thanks in advanced.

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2360
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Lexicon Entries Overriding Each Other

#2 Post by Ocelot »

Well, it correctly highlights Visual Novel, which is in lexicon.
If you are using RenPy 8, then you can try to swap entries for Visual Novel and Visual Novel Writer. If you are using RenPy 7, you are out of luck here and will need to rewrite parts of code to usong a list or something else ordered.
< < insert Rick Cook quote here > >

BeepBoop
Newbie
Posts: 6
Joined: Wed Jul 26, 2023 1:26 pm
Contact:

Re: Lexicon Entries Overriding Each Other

#3 Post by BeepBoop »

I'm using Renpy 8.

But how do I get it to highlight both Visual Novel AND Visual Novel Writer?

User avatar
m_from_space
Miko-Class Veteran
Posts: 888
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Lexicon Entries Overriding Each Other

#4 Post by m_from_space »

BeepBoop wrote: Tue Nov 21, 2023 5:27 pm I'm using Renpy 8.

But how do I get it to highlight both Visual Novel AND Visual Novel Writer?
No offense, but how low IQ do you imagine your players to be if they don't know what a writer is? :lol:

I don't think you have a problem here, just remove that entry. You could of course just explain what a "writer" is. I am still a bit laughing.

BeepBoop
Newbie
Posts: 6
Joined: Wed Jul 26, 2023 1:26 pm
Contact:

Re: Lexicon Entries Overriding Each Other

#5 Post by BeepBoop »

m_from_space wrote: Wed Nov 22, 2023 12:10 pm
No offense, but how low IQ do you imagine your players to be if they don't know what a writer is? :lol:

I don't think you have a problem here, just remove that entry. You could of course just explain what a "writer" is. I am still a bit laughing.
As mentioned in my post I was using them as examples. They're not going to actually be in there. :lol:

Post Reply

Who is online

Users browsing this forum: No registered users