[Solved] How to code text-based endings gallery please?

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
User avatar
Rinzamakani
Regular
Posts: 74
Joined: Wed Aug 16, 2017 3:23 pm
Completed: Love's Apathy (Ciro route), A Frigid Space, Telechronic Static
Projects: Love's Apathy (Full)
itch: rinzamakani.itch.io
Contact:

[Solved] How to code text-based endings gallery please?

#1 Post by Rinzamakani »

Hello. :) I remembered today that someone who played a game I made requested that I make an endings list for all the characters in the game.
I figured I could place the ending list in the image gallery I have under a tab named "Others" or "Extras".

My problem is, I don't know how to actually code the screen for it.

This is part of the code to my gallery:

Code: Select all

screen gallery_b():

    default cg_page_b = 1

    zorder 100
    tag menu

    hbox:
        style_prefix "gallery_stuff"

        ## Our buttons for the pages of Character B's Gallery section.
        textbutton _("1") action SetLocalVariable("cg_page_b", 1)
        textbutton _("2") action SetLocalVariable("cg_page_b", 2)

    showif cg_page_b == 1:
        grid 2 2:
            style_prefix "gallery_stuff"

            ## Replace one null with one button created according to this structure:
            ## add g.make_button("CG_Button_Name", "path/Unlocked_Thumbnail.png", "path/Locked_Thumbnail.png")
            add g.make_button("CG7_Button", "images/char1cgthumb.png", "images/thumbnail_locked.png")
            add g.make_button("CG8_Button", "images/char2cgthumb.png", "images/thumbnail_locked.png")
            add g.make_button("CG9_Button", "images/char3cgthumb.png", "images/thumbnail_locked.png")
            add g.make_button("CG10_Button", "images/char4cgthumb.png", "images/thumbnail_locked.png")

    elif cg_page_b == 2:
        grid 2 2:
            style_prefix "gallery_stuff"

            ## Replace one null with one button created according to this structure:
            ## add g.make_button("CG_Button_Name", "path/Unlocked_Thumbnail.png", "path/Locked_Thumbnail.png")
            add g.make_button("CG11_Button", "images/char5cgthumb.png", "images/thumbnail_locked.png")
            add g.make_button("CG12_Button", "images/char6cgthumb.png", "images/thumbnail_locked.png")
            null
            null
But a CG section isn't what I'm looking to code. I'd like the endings gallery to be completely text-based since many of my endings don't have CGs to show.

Here is an example of what I'm trying to code.
Image
How would I achieve this type of screen exactly? Would it be easy to allow players to replay these endings when they click on them in the gallery screen? I'm assuming the code would go into the screens.rpy as well.
Last edited by Rinzamakani on Tue Feb 02, 2021 6:50 pm, edited 1 time in total.

User avatar
Jackkel Dragon
Veteran
Posts: 283
Joined: Mon Mar 31, 2014 7:17 pm
Organization: Nightshade, Team Despair
itch: jackkel-dragon
Location: USA
Contact:

Re: How to code text-based endings gallery please?

#2 Post by Jackkel Dragon »

Not at my main computer so I can't go into details at the moment, but if you want the buttons to lead to replays of the scenes in question, look into the replay functionality. (It might be in the same part of the documentation as the galleries.)

In general, you'll want to check persistent variables or "label_seen" to find out if an ending has been seen, then display text or a textbutton if that is true.

Don't recall the exact syntax at the moment, but in pseudocode the basic idea is:

if (endingseen):
text "Ending A"

There are clean ways to do a bunch in limited code, but you may want to start by just getting something to work.

As for where to put it, you can put screens in any rpy file, but using screens.rpy can keep everything in one place.
Main Website
Includes information about and links to many of my current and past projects.

Major Game Projects
[Nightshade] Eldritch Academy, Eldritch University, Blooming Nightshade, Flowering Nightshade, Life as Designed
[Team Despair] Corpse Party D2 series

User avatar
Rinzamakani
Regular
Posts: 74
Joined: Wed Aug 16, 2017 3:23 pm
Completed: Love's Apathy (Ciro route), A Frigid Space, Telechronic Static
Projects: Love's Apathy (Full)
itch: rinzamakani.itch.io
Contact:

Re: How to code text-based endings gallery please?

#3 Post by Rinzamakani »

Jackkel Dragon wrote: Tue Feb 02, 2021 12:16 pm Not at my main computer so I can't go into details at the moment, but if you want the buttons to lead to replays of the scenes in question, look into the replay functionality. (It might be in the same part of the documentation as the galleries.)

In general, you'll want to check persistent variables or "label_seen" to find out if an ending has been seen, then display text or a textbutton if that is true.

Don't recall the exact syntax at the moment, but in pseudocode the basic idea is:

if (endingseen):
text "Ending A"

There are clean ways to do a bunch in limited code, but you may want to start by just getting something to work.

As for where to put it, you can put screens in any rpy file, but using screens.rpy can keep everything in one place.
I think I understand what you're saying. Is it something like...

Code: Select all

        textbutton _("Char1") action Show("gallery_a")
        if persistent.Char2route == False:
            textbutton _("???")
        if persistent.Char2route == True:
           textbutton _("Char2") action Show("gallery_b")
        if persistent.Char2routeend == False:
           textbutton _("???")
        if persistent.Char2routeend == True:
           textbutton _("Bonuses") action Start("bonuscontent")
So it would be something along the lines of...

Code: Select all

if persistent.char1Ending1 == False:
text _ ("End 1: ")
if persistent.char1Ending1 == True:
text _ ("End 1: Name of ending")
I'm not 100% sure if that's correct.

User avatar
Jackkel Dragon
Veteran
Posts: 283
Joined: Mon Mar 31, 2014 7:17 pm
Organization: Nightshade, Team Despair
itch: jackkel-dragon
Location: USA
Contact:

Re: How to code text-based endings gallery please?

#4 Post by Jackkel Dragon »

That looks pretty close to something that should work. I'd recommend seeing how the code runs in-game and tweaking from there.

Now that I'm at a slightly better device, here's a loose idea of how I might code something like this (not exact code, but I'll try to be close):

Code: Select all

screen endlist(): ## skipping most code for the important bits
    vbox:
        label "Endings"

        ## important code below
        if (persistent.endingA):
            textbutton "Ending A" action Replay("endingA")
        else: ## also recognizes "None", if endingA has never been set
            text "???"

        ## and so on...
If you have a lot of endings and know a bit of Python, you can also make a for loop to handle it:

Code: Select all

endings = []
endings.append(("persistent.endingA", "???", "Ending A", "endingA")) ## tuple of (variable, unseen text, seen text, label)

vbox:
    for e in endings:
        if e[0]:
            textbutton e[2] action Replay(e[3])
        else:
            text e[1]
I recommend trying your code or the first example here first, though. I wrote the examples and I second-guessed a few of the decisions. (They should both work, but may be tedious or complicated to implement.)

Hopefully this wasn't too confusing. Let us know if you still need help looking into this.
Main Website
Includes information about and links to many of my current and past projects.

Major Game Projects
[Nightshade] Eldritch Academy, Eldritch University, Blooming Nightshade, Flowering Nightshade, Life as Designed
[Team Despair] Corpse Party D2 series

User avatar
Rinzamakani
Regular
Posts: 74
Joined: Wed Aug 16, 2017 3:23 pm
Completed: Love's Apathy (Ciro route), A Frigid Space, Telechronic Static
Projects: Love's Apathy (Full)
itch: rinzamakani.itch.io
Contact:

Re: How to code text-based endings gallery please?

#5 Post by Rinzamakani »

Jackkel Dragon wrote: Tue Feb 02, 2021 1:57 pm That looks pretty close to something that should work. I'd recommend seeing how the code runs in-game and tweaking from there.

Now that I'm at a slightly better device, here's a loose idea of how I might code something like this (not exact code, but I'll try to be close):

Code: Select all

screen endlist(): ## skipping most code for the important bits
    vbox:
        label "Endings"

        ## important code below
        if (persistent.endingA):
            textbutton "Ending A" action Replay("endingA")
        else: ## also recognizes "None", if endingA has never been set
            text "???"

        ## and so on...
If you have a lot of endings and know a bit of Python, you can also make a for loop to handle it:

Code: Select all

endings = []
endings.append(("persistent.endingA", "???", "Ending A", "endingA")) ## tuple of (variable, unseen text, seen text, label)

vbox:
    for e in endings:
        if e[0]:
            textbutton e[2] action Replay(e[3])
        else:
            text e[1]
I recommend trying your code or the first example here first, though. I wrote the examples and I second-guessed a few of the decisions. (They should both work, but may be tedious or complicated to implement.)

Hopefully this wasn't too confusing. Let us know if you still need help looking into this.
When I tried this, it gave me:

Code: Select all

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


File "game/Ending_gallery.rpy", line 1: screen expects a non-empty block.
    screen Ending_gallery():
                            ^

File "game/Ending_gallery.rpy", line 3: expected statement.
    text_("Char1 End 1: ???")
                            ^

File "game/Ending_gallery.rpy", line 5: expected statement.
    text_("Char1 End 1: True end")
                                 ^

File "game/Ending_gallery.rpy", line 7: expected statement.
    text_("Char2 End 1: ???")
                                 ^

File "game/Ending_gallery.rpy", line 9: expected statement.
    text_("Char2 End 1: True Ending")
                                         ^

Ren'Py Version: Ren'Py 7.3.5.606
Tue Feb 02 12:13:16 2021
This is the code I tried:

Code: Select all

   if persistent.Char1Ending1 == False:
      show text_("Char1 End 1: ???")
   if persistent.CharEnding1 == True:
      show text_("Char1 End 1: True end")
   if persistent.Char2Ending1 == False:
      show text_("Char2 End 1: ???")
   if persistent.Char2Ending1 == True:
      show text_("Char2 End 1: True Ending")
I don't understand the code you gave me for:

Code: Select all

endings = []
endings.append(("persistent.endingA", "???", "Ending A", "endingA")) ## tuple of (variable, unseen text, seen text, label)

vbox:
    for e in endings:
        if e[0]:
            textbutton e[2] action Replay(e[3])
        else:
            text e[1]
Is there a way I can add scrollbar if there are too many endings? I'm also okay with only listing the endings and not making them replayable if it's easier.

edit: I got something working, sort of. This is the code I used:

Code: Select all

screen Ending_gallery():
   tag menu
   frame:
        background "images/whatever.png"
        vbox:
            xalign 1.0
            xoffset 30
            xmaximum 1100
            yalign 1.0
            yoffset 30
        label "Endings"
        ## important code below
        if (persistent.endingA):
            textbutton "Ending A" action Replay("endingA")
        else: ## also recognizes "None", if endingA has never been set
            text "???"
This happens:
Image

User avatar
_ticlock_
Miko-Class Veteran
Posts: 910
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: How to code text-based endings gallery please?

#6 Post by _ticlock_ »

EDIT: Sorry, I answered the wrong post

User avatar
_ticlock_
Miko-Class Veteran
Posts: 910
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: How to code text-based endings gallery please?

#7 Post by _ticlock_ »

Rinzamakani wrote: Tue Feb 02, 2021 2:22 pm Is there a way I can add scrollbar if there are too many endings? I'm also okay with only listing the endings and not making them replayable if it's easier.
Hi, Rinzamakani,
You can use game_menu to make it in the same design and add scrollbar. For example, if you put the Ending_gallery button in the navigation screen (screens.rpy)

Code: Select all

screen navigation:
    ...
        textbutton _("Preferences") action ShowMenu("preferences")

        textbutton _("Ending_gallery") action ShowMenu("Ending_gallery")
You can define your screen like this:

Code: Select all

screen Ending_gallery():
   tag menu
   use game_menu(_("Ending_gallery"), scroll="viewport"):
        vbox:
            xalign 1.0
            xoffset 30
            xmaximum 1100
            yalign 1.0
            yoffset 30
            label "Endings"
            ## important code below
            if (persistent.endingA):
                textbutton "Ending A" action Replay("endingA")
            else: ## also recognizes "None", if endingA has never been set
                text "???"

User avatar
Rinzamakani
Regular
Posts: 74
Joined: Wed Aug 16, 2017 3:23 pm
Completed: Love's Apathy (Ciro route), A Frigid Space, Telechronic Static
Projects: Love's Apathy (Full)
itch: rinzamakani.itch.io
Contact:

Re: How to code text-based endings gallery please?

#8 Post by Rinzamakani »

_ticlock_ wrote: Tue Feb 02, 2021 5:30 pm
Rinzamakani wrote: Tue Feb 02, 2021 2:22 pm Is there a way I can add scrollbar if there are too many endings? I'm also okay with only listing the endings and not making them replayable if it's easier.
Hi, Rinzamakani,
You can use game_menu to make it in the same design and add scrollbar. For example, if you put the Ending_gallery button in the navigation screen (screens.rpy)

Code: Select all

screen navigation:
    ...
        textbutton _("Preferences") action ShowMenu("preferences")

        textbutton _("Ending_gallery") action ShowMenu("Ending_gallery")
You can define your screen like this:

Code: Select all

screen Ending_gallery():
   tag menu
   use game_menu(_("Ending_gallery"), scroll="viewport"):
        vbox:
            xalign 1.0
            xoffset 30
            xmaximum 1100
            yalign 1.0
            yoffset 30
            label "Endings"
            ## important code below
            if (persistent.endingA):
                textbutton "Ending A" action Replay("endingA")
            else: ## also recognizes "None", if endingA has never been set
                text "???"
Thank you. This worked. Much appreciated! :)

User avatar
Jackkel Dragon
Veteran
Posts: 283
Joined: Mon Mar 31, 2014 7:17 pm
Organization: Nightshade, Team Despair
itch: jackkel-dragon
Location: USA
Contact:

Re: [Solved] How to code text-based endings gallery please?

#9 Post by Jackkel Dragon »

Sounds like you figured it out, but it looks like the reason the first attempt had everything on top of each other is because of improper indentation. Make sure that elements that rely on something else are indented unless something is designed otherwise. (In that case, things inside the vbox needed to be on the next indent layer.)

You can also make scrollbars without using the game menu screen as a base, but I highly recommend using the game menu (as in the code above) unless you need a specific look. It lets you focus more on the insides of the viewport rather than trying to get the right size and scrolling behavior when you take advantage of the "use" command. As someone who has worked with viewports a lot, I can safely say that it's great to not need to mess with them more than necessary.
Main Website
Includes information about and links to many of my current and past projects.

Major Game Projects
[Nightshade] Eldritch Academy, Eldritch University, Blooming Nightshade, Flowering Nightshade, Life as Designed
[Team Despair] Corpse Party D2 series

User avatar
Rinzamakani
Regular
Posts: 74
Joined: Wed Aug 16, 2017 3:23 pm
Completed: Love's Apathy (Ciro route), A Frigid Space, Telechronic Static
Projects: Love's Apathy (Full)
itch: rinzamakani.itch.io
Contact:

Re: [Solved] How to code text-based endings gallery please?

#10 Post by Rinzamakani »

Jackkel Dragon wrote: Tue Feb 02, 2021 8:09 pm Sounds like you figured it out, but it looks like the reason the first attempt had everything on top of each other is because of improper indentation. Make sure that elements that rely on something else are indented unless something is designed otherwise. (In that case, things inside the vbox needed to be on the next indent layer.)

You can also make scrollbars without using the game menu screen as a base, but I highly recommend using the game menu (as in the code above) unless you need a specific look. It lets you focus more on the insides of the viewport rather than trying to get the right size and scrolling behavior when you take advantage of the "use" command. As someone who has worked with viewports a lot, I can safely say that it's great to not need to mess with them more than necessary.
I actually ran into a new problem once everything was coded with the player's custom name not showing up in the replays. I'll probably make a separate thread for that later.

User avatar
Jackkel Dragon
Veteran
Posts: 283
Joined: Mon Mar 31, 2014 7:17 pm
Organization: Nightshade, Team Despair
itch: jackkel-dragon
Location: USA
Contact:

Re: [Solved] How to code text-based endings gallery please?

#11 Post by Jackkel Dragon »

There are a few options for dealing with that, but it depends on how you want to handle things. Off the top of my head, the main options would be having the player set their custom name in the preferences menu as a config value (maybe with the option of changing it in-game from a new game) or have a replay-specific function or label to ask for a name before a replay begins. It ultimately depends on how you want the player to control the name and what feels like a good presentation.
Main Website
Includes information about and links to many of my current and past projects.

Major Game Projects
[Nightshade] Eldritch Academy, Eldritch University, Blooming Nightshade, Flowering Nightshade, Life as Designed
[Team Despair] Corpse Party D2 series

Post Reply

Who is online

Users browsing this forum: Google [Bot], Vamp-sama