[Solved] Glossary Issue - Starts Bugging 4 days into the Game

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.
Message
Author
User avatar
Mello-Knight
Regular
Posts: 43
Joined: Fri Feb 24, 2017 10:42 am
Projects: Band Camp Boyfriend
Tumblr: lovebirdgames
Contact:

[Solved] Glossary Issue - Starts Bugging 4 days into the Game

#1 Post by Mello-Knight »

Hello, this Mello, back at it again with another programming bug/question!

I am currently working on implementing a glossary feature into my game, Band Camp Boyfriend. Every so often you will encounter a highlighted word and you can click it so a little vocabulary card with the definition will pop up. Here is an example where I show off the feature in a tumblr post: https://lovebirdgames.tumblr.com/post/6 ... gramming-a

Below, in the link at the bottom, is how I've been approaching the programming. There are three pictures put together. In script.rpy, each glossary card gets the usual line of code for where it lives. In each chapter of the game, a piece of code lives at the bottom of the document relating to the card that appears in that chapter. And then there is the code that surrounds the specific word.

All seems to be in working order until I reach the fourth day of the game. I can open glossary cards, but I cannot get out of them without exiting the game. In the first three days, all it takes it a simple click and I'm back on track, but after that, I am trapped. I don't understand what the issue could be since I have been copying and pasting the blocks of code and making changes where needed.

What could be the reason for this? Is it an easy fix or perhaps there is a better way of approaching the implementation of a glossary?

Thanks in advance for any help you can offer!

https://imgur.com/a/s6QKJul
Last edited by Mello-Knight on Tue May 31, 2022 10:34 pm, edited 1 time in total.

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: Glossary Issue - Starts Bugging 4 days into the Game

#2 Post by zmook »

Can you post the actual code for the entry that you're having trouble with? Is it the "atten-hut" one? It looks like you've just coded your glossary entries as "call a label; show an image; pause; return." Which I suppose is fine, except "return" does not in fact hide the image you've shown. Possibly you're following up the working ones with 'scene' statements, which implicitly hide everything previously showing, and hence clean up your glossary images.
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

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

Re: Glossary Issue - Starts Bugging 4 days into the Game

#3 Post by m_from_space »

My way to implement a glossary: The glossary data itself can be put inside a dict that is shown via a screen. We then have to create a hyperlink handler, since the normal handlers cannot take arguments as far as i know. After that, adding a new word is super easy. You don't have to add anything else inside your chapters, just add a new entry to the "glossary_entries" dictionary.

Code: Select all

init python:
    # our own hyperlink handler
    def glossary_hyperlink(word):
        # if the player clicks on the link and the screen is already there, let's close the glossary, otherwise show it
        if renpy.get_screen("glossary_screen"):
            renpy.hide_screen("glossary_screen")
        else:
            renpy.show_screen("glossary_screen", word, glossary_entries[word])
        renpy.restart_interaction()

    config.hyperlink_handlers['glossary'] = glossary_hyperlink

define glossary_entries = {
    'word1': 'explanation for word1',
    'word2': 'explanation for word2'
}

screen glossary_screen(word, explanation):
    # make sure the player cannot interact with other stuff while here
    modal True
    # renpy 8.0 allows this new displayable that activates when the player doesn't click on an object, but elsewhere
    # uncomment if you wanna use it
    # dismiss action Hide("glossary_screen")
    vbox:
        xalign 0.5 yalign 0.5
        text "Glossary for [word]"
        text "[explanation]"
        # optional close button
        textbutton "Close Glossary" action Hide("glossary_screen")

label start:
    "Here you can look up this {a=glossary:word1}WORD1{/a}"
    "But maybe you want to find out about {a=glossary:word2}this word{/a} instead."

User avatar
Mello-Knight
Regular
Posts: 43
Joined: Fri Feb 24, 2017 10:42 am
Projects: Band Camp Boyfriend
Tumblr: lovebirdgames
Contact:

Re: Glossary Issue - Starts Bugging 4 days into the Game

#4 Post by Mello-Knight »

zmook wrote: Sat May 28, 2022 10:21 pm Can you post the actual code for the entry that you're having trouble with? Is it the "atten-hut" one? It looks like you've just coded your glossary entries as "call a label; show an image; pause; return." Which I suppose is fine, except "return" does not in fact hide the image you've shown. Possibly you're following up the working ones with 'scene' statements, which implicitly hide everything previously showing, and hence clean up your glossary images.
Thank you for the response. Atten-hut is one that works so I grabbed a glossary card from Day 4 in the game (drilldown), which is where the glossary stops functioning properly.

https://imgur.com/a/qfHkBFA

I tried adding a "hide drilldown at glossary with dissolve" before the return command, but it didn't fix the issue. It worked for trying it on a Day 1 card, but I can't figure out why Day 4 and on quits on me.

User avatar
Mello-Knight
Regular
Posts: 43
Joined: Fri Feb 24, 2017 10:42 am
Projects: Band Camp Boyfriend
Tumblr: lovebirdgames
Contact:

Re: Glossary Issue - Starts Bugging 4 days into the Game

#5 Post by Mello-Knight »

m_from_space wrote: Sun May 29, 2022 2:36 am My way to implement a glossary: The glossary data itself can be put inside a dict that is shown via a screen. We then have to create a hyperlink handler, since the normal handlers cannot take arguments as far as i know. After that, adding a new word is super easy. You don't have to add anything else inside your chapters, just add a new entry to the "glossary_entries" dictionary.

Code: Select all

init python:
    # our own hyperlink handler
    def glossary_hyperlink(word):
        # if the player clicks on the link and the screen is already there, let's close the glossary, otherwise show it
        if renpy.get_screen("glossary_screen"):
            renpy.hide_screen("glossary_screen")
        else:
            renpy.show_screen("glossary_screen", word, glossary_entries[word])
        renpy.restart_interaction()

    config.hyperlink_handlers['glossary'] = glossary_hyperlink

define glossary_entries = {
    'word1': 'explanation for word1',
    'word2': 'explanation for word2'
}

screen glossary_screen(word, explanation):
    # make sure the player cannot interact with other stuff while here
    modal True
    # renpy 8.0 allows this new displayable that activates when the player doesn't click on an object, but elsewhere
    # uncomment if you wanna use it
    # dismiss action Hide("glossary_screen")
    vbox:
        xalign 0.5 yalign 0.5
        text "Glossary for [word]"
        text "[explanation]"
        # optional close button
        textbutton "Close Glossary" action Hide("glossary_screen")

label start:
    "Here you can look up this {a=glossary:word1}WORD1{/a}"
    "But maybe you want to find out about {a=glossary:word2}this word{/a} instead."
Thanks so much for this. I'm still trying to see if I can get the code I currently have working so I don't have to do a big overhaul, but this is a good fallback. Would it be possible to do this with image files I created instead of just typing in the text? Since I made near a hundred glossary cards it would be great to be able to use those. ^^'

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: Glossary Issue - Starts Bugging 4 days into the Game

#6 Post by zmook »

Mello-Knight wrote: Sun May 29, 2022 11:40 am I tried adding a "hide drilldown at glossary with dissolve" before the return command, but it didn't fix the issue. It worked for trying it on a Day 1 card, but I can't figure out why Day 4 and on quits on me.
Wait, what do you mean "quits on you"? Is there an error message?

Anyway, I think I need to see more code than this. what comes after the line with "{a=call:drilldown}" in it? I do notice one difference: you had just "{a=attenhut}" in the previous example, leaving out the "call:" protocol. Though it seems to me from the docs that "{a=call:drilldown}" should be the correct one, and "{a=attenhut}" looks suspicious. If you have a 'return' statement without a corresponding prior 'call', renpy will take that as an instruction to exit the game.

Anyway, also: please post code as text with [code]...[/code] markup, rather than as screenshots. It's a lot easier to read and quote in replies that way.
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

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

Re: Glossary Issue - Starts Bugging 4 days into the Game

#7 Post by Ocelot »

zmook wrote: Sun May 29, 2022 12:14 pm Anyway, I think I need to see more code than this. what comes after the line with "{a=call:drilldown}" in it? I do notice one difference: you had just "{a=attenhut}" in the previous example, leaving out the "call:" protocol. Though it seems to me from the docs that "{a=call:drilldown}" should be the correct one, and "{a=attenhut}" looks suspicious. If you have a 'return' statement without a corresponding prior 'call', renpy will take that as an instruction to exit the game.
Default protocol handler is call_in_new_context, so unless you change corresponding configuration value, it should be fine. But if you did change it to jump, then yes, you are likely to experience similar problems.
< < insert Rick Cook quote here > >

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

Re: Glossary Issue - Starts Bugging 4 days into the Game

#8 Post by m_from_space »

Mello-Knight wrote: Sun May 29, 2022 11:43 amThanks so much for this. I'm still trying to see if I can get the code I currently have working so I don't have to do a big overhaul, but this is a good fallback. Would it be possible to do this with image files I created instead of just typing in the text? Since I made near a hundred glossary cards it would be great to be able to use those. ^^'
Sure, you are not limited to text, you can show whatever you want inside the glossary screen. You could for example name every one of your card like the word you are referring to internally and then just load it inside the screen. Try to understand my code first and you will see yourself. It's really not hard, I promise. ;)

Code: Select all

# You need to have an image named "attenhut.jpg" or "attenhut.png" in your images folder.

screen glossary_screen(word):
    modal True
    add word
    #...
    
label start:
    "Here is the glossary entry for {a=glossary:attenhut}Atten-Hut{/a} as an image."

User avatar
Mello-Knight
Regular
Posts: 43
Joined: Fri Feb 24, 2017 10:42 am
Projects: Band Camp Boyfriend
Tumblr: lovebirdgames
Contact:

Re: Glossary Issue - Starts Bugging 4 days into the Game

#9 Post by Mello-Knight »

zmook wrote: Sun May 29, 2022 12:14 pm
Mello-Knight wrote: Sun May 29, 2022 11:40 am I tried adding a "hide drilldown at glossary with dissolve" before the return command, but it didn't fix the issue. It worked for trying it on a Day 1 card, but I can't figure out why Day 4 and on quits on me.
Wait, what do you mean "quits on you"? Is there an error message?

Anyway, I think I need to see more code than this. what comes after the line with "{a=call:drilldown}" in it? I do notice one difference: you had just "{a=attenhut}" in the previous example, leaving out the "call:" protocol. Though it seems to me from the docs that "{a=call:drilldown}" should be the correct one, and "{a=attenhut}" looks suspicious. If you have a 'return' statement without a corresponding prior 'call', renpy will take that as an instruction to exit the game.

Anyway, also: please post code as text with [code]...[/code] markup, rather than as screenshots. It's a lot easier to read and quote in replies that way.
Wow, I am so sorry for not posting the code as text and moronically making life more difficult for the both of us! (X_X)

Sorry, by quits on me, I mean it gets stuck with the glossary card on the screen. I can click all I want, but I can't get out of it unless I close out of the game or right click and load up a different save file. I tried altering the code with the a=call_in_new_context command, but the results have not been changed.

Here is an example of the code on Day 1, where everything is working fine...

Code: Select all

    show wiley determined2 at center with qd
    w "Well kids, that’s all for tonight. Go {a=call_in_new_context:totheready}{color=#ff8190}{u}to the ready!{/u}{/color}{/a}"

    stop music fadeout 1.5

#keep ambience going

    "Everyone spreads their legs at shoulder width, lets their arms fall to their sides, and bows their heads." 
    "We stand quietly, waiting for the signal. Some of the freshmen glance around in wonderment before following suit."

    play sound wiley_bandtenhut
    show wiley soundoff at center with vpunch
    w "Band…{a=call_in_new_context:attenhut}{color=#ff8190}{u}atten-hut!{/u}{/color}{/a}"

    play sound sfx_drum_soundoff
    pause 1.0

    band "{a=call_in_new_context:bmbmb}{color=#ff8190}{u}B M B M B!{/u}{/color}{/a}"
    stop sound

    show wiley srs at center with qd
    "We all snap to attention on the final ‘B’, our chins high and our eyes blazing with pride." 
    "After an electric moment, Mr. Wiley grins back at us."
At the bottom of this document, I have blocks of code for each vocab word that appears in Day 1. They look like this.

Code: Select all

label attenhut:
    play sound sfx_pause
    window hide
    show attenhut at glossary with dissolve
    pause
    hide attenhut at glossary with dissolve
    return
Now here is an excerpt from Day 4, where the glossary ceases working.

Code: Select all

    stop music fadeout 1.0
    show wiley determined2 at center with qd
    w "We’re going to wrap up this basics session with a {a=call_in_new_context:drilldown}{color=#ff8190}{u}drilldown!{/u}{/color}{/a}"

    "Oh. That actually is pretty exciting. We haven’t had a drilldown in forever!"

Again, at the bottom of this document, I have the rest of the code.

Code: Select all

label drilldown:
    play sound sfx_pause
    window hide
    show drilldown at glossary with dissolve
    pause
    hide drilldown at glossary with dissolve
    return
I feel like if anything the problem lies within the return command, but why does it start failing on the fourth day of the game? Is it too many scripts for it to handle? Should I be consolidating all of the label code blocks into one document instead of spreading them out on what day their on? Not necessarily asking you these questions, just voicing thoughts that have been plaguing me lol.

Thanks for all your patience with me.

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: Glossary Issue - Starts Bugging 4 days into the Game

#10 Post by zmook »

Okay, this is a puzzle.

- It's vaguely conceivable that you could have "too many scripts" if you do a lot of 'call' statements without ever returning from them. But in that case you should get a crash with a 'recursion depth exceeded' error, which is not your problem.
- No, don't consolidate your code into one document. Renpy is happier with many small files than one big one.

I understand that your actual visible error is that the game gets stuck and refuses to advance no matter where you click or what key you press. Is that correct?

Could you look at the log.txt file in the top level of your project directory? (ie, it's beside the 'game' folder, not within it.) After you quit to escape from a stuck game, is there anything that looks like an error at the bottom?

Do you have the developer console enabled? I think it should be, unless for some reason you have disabled it. At the point where you get stuck, please put your mouse in the middle of the screen and hit "shift-I" (capital 'i'). What screens does it think are visible? Is there anything you don't expect, that might be stealing your input events? If you don't know how to interpret it, you might have to take a screenshot to share it here.

Hit "shift-O" (capital 'o') to open the console. Enter

Code: Select all

renpy.get_return_stack()
. You might have to take a screenshot to share that, too.
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

User avatar
Mello-Knight
Regular
Posts: 43
Joined: Fri Feb 24, 2017 10:42 am
Projects: Band Camp Boyfriend
Tumblr: lovebirdgames
Contact:

Re: Glossary Issue - Starts Bugging 4 days into the Game

#11 Post by Mello-Knight »

zmook wrote: Sun May 29, 2022 6:52 pm Okay, this is a puzzle.

- It's vaguely conceivable that you could have "too many scripts" if you do a lot of 'call' statements without ever returning from them. But in that case you should get a crash with a 'recursion depth exceeded' error, which is not your problem.
- No, don't consolidate your code into one document. Renpy is happier with many small files than one big one.

I understand that your actual visible error is that the game gets stuck and refuses to advance no matter where you click or what key you press. Is that correct?

Could you look at the log.txt file in the top level of your project directory? (ie, it's beside the 'game' folder, not within it.) After you quit to escape from a stuck game, is there anything that looks like an error at the bottom?

Do you have the developer console enabled? I think it should be, unless for some reason you have disabled it. At the point where you get stuck, please put your mouse in the middle of the screen and hit "shift-I" (capital 'i'). What screens does it think are visible? Is there anything you don't expect, that might be stealing your input events? If you don't know how to interpret it, you might have to take a screenshot to share it here.

Hit "shift-O" (capital 'o') to open the console. Enter

Code: Select all

renpy.get_return_stack()
. You might have to take a screenshot to share that, too.
In regards to your question, yes, the game is getting stuck. You are correct.

Nothing looks like an error in log.txt to me...here's what's at the bottom.

Code: Select all

Number of texture units: 8
Using shader environment.
Using FBO RTT.
Root FBO is: 0
FBO Maximum Texture Size: 2048
Using gl renderer.
Texture testing:
- Hardware max texture size: 8192
- 64px textures work.
- 128px textures work.
- 256px textures work.
- 512px textures work.
- 1024px textures work.
- 2048px textures work.
Root FBO is: 0
FBO Maximum Texture Size: 2048
Total time until interface ready: 14.3208739758s
- Target is 5 frames in 0.333333333333 seconds.
- Frame drawn at 0.000000 seconds.
- Frame drawn at 0.013770 seconds.
- Frame drawn at 0.030818 seconds.
- Frame drawn at 0.046887 seconds.
- Frame drawn at 0.063019 seconds.
- 0.063019 seconds to render 5 frames.
I tried Shift+I and here are my results...it looks all right to me and matched a working glossary card when I compared them.

https://imgur.com/FO0UIUN

I tried Shift+O next and after some lovely frustration with the command being hidden by the day bug, I achieved...uhh...well, nothing really happened. I've never used these commands so I wasn't sure what to expect.

https://imgur.com/EKSbUSd

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

Re: Glossary Issue - Starts Bugging 4 days into the Game

#12 Post by Ocelot »

Ok, empty stack is what is expected for call_in_new_context. Can you check what happens if you replace call_in_new_context with call (it will mess with text - automaitcally advance it after showing glossary- but right now I want to see if bug will persist).

In addition, do the same things you did, but:
1. use Shift+Alt+I to open displayable inspector (will show additional displayables)
2. get_return_stack now will actually show somethiong now, when it is not hidden by new context.
< < insert Rick Cook quote here > >

User avatar
Mello-Knight
Regular
Posts: 43
Joined: Fri Feb 24, 2017 10:42 am
Projects: Band Camp Boyfriend
Tumblr: lovebirdgames
Contact:

Re: Glossary Issue - Starts Bugging 4 days into the Game

#13 Post by Mello-Knight »

m_from_space wrote: Sun May 29, 2022 1:30 pm
Mello-Knight wrote: Sun May 29, 2022 11:43 amThanks so much for this. I'm still trying to see if I can get the code I currently have working so I don't have to do a big overhaul, but this is a good fallback. Would it be possible to do this with image files I created instead of just typing in the text? Since I made near a hundred glossary cards it would be great to be able to use those. ^^'
Sure, you are not limited to text, you can show whatever you want inside the glossary screen. You could for example name every one of your card like the word you are referring to internally and then just load it inside the screen. Try to understand my code first and you will see yourself. It's really not hard, I promise. ;)

Code: Select all

# You need to have an image named "attenhut.jpg" or "attenhut.png" in your images folder.

screen glossary_screen(word):
    modal True
    add word
    #...
    
label start:
    "Here is the glossary entry for {a=glossary:attenhut}Atten-Hut{/a} as an image."
We're dabbling with this. The code works, but is there an easy way to position the image? We tried inputting some positioning/anchoring adjustments, but it just crashed the game. If possible, where would we put the code?

User avatar
Mello-Knight
Regular
Posts: 43
Joined: Fri Feb 24, 2017 10:42 am
Projects: Band Camp Boyfriend
Tumblr: lovebirdgames
Contact:

Re: Glossary Issue - Starts Bugging 4 days into the Game

#14 Post by Mello-Knight »

Ocelot wrote: Mon May 30, 2022 1:31 pm Ok, empty stack is what is expected for call_in_new_context. Can you check what happens if you replace call_in_new_context with call (it will mess with text - automaitcally advance it after showing glossary- but right now I want to see if bug will persist).

In addition, do the same things you did, but:
1. use Shift+Alt+I to open displayable inspector (will show additional displayables)
2. get_return_stack now will actually show somethiong now, when it is not hidden by new context.
That didn't work either, but thank you! :') We are going to go with m_from_space's suggestion since it makes sense to set it up as a screen rather than a label. The cards that were not working before are working on it, but it's just a matter of positioning the image, which hopefully is doable.

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

Re: Glossary Issue - Starts Bugging 4 days into the Game

#15 Post by m_from_space »

Mello-Knight wrote: Mon May 30, 2022 2:11 pmWe're dabbling with this. The code works, but is there an easy way to position the image? We tried inputting some positioning/anchoring adjustments, but it just crashed the game. If possible, where would we put the code?

Of course you can position the image, I just gave you a very basic example. ^^

What exactly lead to the game crashing? You should provide useful information to let others help you.

Looking at your game code I assume the glossary screen should look like this:

Code: Select all

screen glossary_screen(word):
    modal True
    # the following line only works with renpy 7.5/8.0
    dismiss action Hide("glossary_screen", transition=dissolve)
    # play sound once the screen shows
    on "show" action Play("sound", audio.sfx_pause)
    # show the glossary image using ATL transform "glossary"
    add word at glossary:
        # positioning of the glossary image in the center of the screen
        xalign 0.5 yalign 0.5
    # alternative: make the image a button, so the player can leave the screen by clicking on it
    # (if the dismiss command above does not work for your game version)
    # imagebutton idle word at glossary:
    #     action Hide("glossary_screen", transition=dissolve)
    #     xalign 0.5 yalign 0.5

Post Reply

Who is online

Users browsing this forum: No registered users