Deleting choices automatically after they have been chosen

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.
Post Reply
Message
Author
User avatar
Aviala
Miko-Class Veteran
Posts: 530
Joined: Tue Sep 03, 2013 8:40 am
Completed: Your Royal Gayness, Our War Everlasting, Love Bug
Organization: Lizard Hazard Games
Tumblr: lizardhazardgames
itch: aviala
Location: Finland
Contact:

Deleting choices automatically after they have been chosen

#1 Post by Aviala » Wed Jan 16, 2019 7:51 am

I tried to find a solution for my dating sim -style game project that features a conversation system. In the game the player can move around freely and they can return to talk to a character whenever. I wanted the engine to delete choices that have already been selected so that each conversation can only be done once. I couldn't find a working solution anywhere so I came up with my own.

Modify your choice screen like this:

Code: Select all

screen choice(items):
    style_prefix "choice"
#using vpgrid ensures there won't be a problem with a varying number of choices; it adds a scroll bar
    vpgrid:

        cols 1
        spacing 10
        draggable True
        mousewheel True
        ymaximum 500
        xmaximum 1300

        scrollbars "vertical"
        side_xalign 0.5
        yalign 0.5

#Check if the item caption is in a list you created and if it is, don't show it
        for i in items:
            if i.caption not in chosen_choices or "{image=images/empty.png}" in i.caption:
                if "{image=images/empty.png}" in i.caption:
                    textbutton i.caption action i.action
                else:
                    textbutton i.caption action i.action, AddToSet(chosen_choices, i.caption)
The idea is that you create a list called chosen_choices (or whatever you want to name it):
default chosen_choices = []

Then you check if a choice is in there and if it is, it won't show up in your choice menu. When you make a choice, that choice is added to the chosen_choices list, so the next time you access the conversation menu it'll be deleted.
The problem with this was that if there's a "leave" choice it shouldn't disappear. So the solution is that the game checks if a certain image is included in the choice caption. The image in question is a 10x10 pixels empty square (but you could make it an arrow or something if you want to).

Example of how you would use the menus:

Code: Select all

        menu:
            "The devil stands next to his hellfire grill."

            "Greet him.":
                jump greet_satan

            "Flirt.":
                jump flirt_satan

            "Leave {image=images/empty.png}":
                "Jumping back to satan station choice"
                jump satan_station
                
So you just include the image in every choice that you want to never be deleted. It's a bit of a weird solution but it's really simple and works perfectly.

User avatar
wyverngem
Miko-Class Veteran
Posts: 613
Joined: Mon Oct 03, 2011 7:27 pm
Completed: Simple as Snow, Lady Luck's Due,
Projects: Aether Skies, Of the Waterfall
Tumblr: casting-dreams
itch: castingdreams
Location: USA
Contact:

Re: Deleting choices automatically after they have been chosen

#2 Post by wyverngem » Thu Jan 31, 2019 7:13 pm

How does it know that the menu item choice is unique? I mean you could have multiple menu's with "Flirt" as the caption even though it with a different character.

User avatar
Aviala
Miko-Class Veteran
Posts: 530
Joined: Tue Sep 03, 2013 8:40 am
Completed: Your Royal Gayness, Our War Everlasting, Love Bug
Organization: Lizard Hazard Games
Tumblr: lizardhazardgames
itch: aviala
Location: Finland
Contact:

Re: Deleting choices automatically after they have been chosen

#3 Post by Aviala » Sat Feb 02, 2019 4:22 am

Good point! I didn't test the solution with multiples of the same choice caption. The easiest way is to make each conversation option unique (like 'Flirt with Satan' instead of just 'Flirt' ) or another, sneaky way would be to make a copy of your invisible image and name it something else, and then add the image to the duplicate choice. That way they'll have unique captions but the player won't see a difference. If you have more than 2 of the same choice caption, just make sure each of them has a different number of invisible images in the caption.

It's not a very elegant solution but it should work. I haven't tested it yet, though. I'll reply here if there are any problems once I test it.

AON
Newbie
Posts: 10
Joined: Tue Oct 31, 2017 9:54 am
Contact:

Re: Deleting choices automatically after they have been chosen

#4 Post by AON » Sat Feb 02, 2019 2:03 pm

Why not let the regular menu do it for you ?

Code: Select all

default onceOnly = []

menu testMenu:
    set onceOnly
    "first choice":
        "this is the first choice"
        jump testMenu
    "second choice":
        "this is the second choice"
        jump testMenu
    "third choice":
        "this is the third choice"
        jump testMenu
    "continue" if len( onceOnly ) == 3:
        return

label start:
    call testMenu
    "finished"

User avatar
Aviala
Miko-Class Veteran
Posts: 530
Joined: Tue Sep 03, 2013 8:40 am
Completed: Your Royal Gayness, Our War Everlasting, Love Bug
Organization: Lizard Hazard Games
Tumblr: lizardhazardgames
itch: aviala
Location: Finland
Contact:

Re: Deleting choices automatically after they have been chosen

#5 Post by Aviala » Tue Feb 05, 2019 8:45 am

How does this work? Like, what's the logic here? I'm self-taught when it comes to renpy coding so I don't always understand how other people's code works.
I just wanted to share a solution that worked for me, but if there are better ways to do it, that's great!
AON wrote:
Sat Feb 02, 2019 2:03 pm
Why not let the regular menu do it for you ?

Code: Select all

default onceOnly = []

menu testMenu:
    set onceOnly
    "first choice":
        "this is the first choice"
        jump testMenu
    "second choice":
        "this is the second choice"
        jump testMenu
    "third choice":
        "this is the third choice"
        jump testMenu
    "continue" if len( onceOnly ) == 3:
        return

label start:
    call testMenu
    "finished"

philat
Eileen-Class Veteran
Posts: 1742
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Deleting choices automatically after they have been chosen

#6 Post by philat » Wed Feb 06, 2019 5:21 am

The set functionality is for some reason undocumented but pretty well-known on the forums. It was briefly broken (not sure why) but should be working now again on the latest builds. Basically, I assume it's the same concept as what your code does -- you give a set to a menu (the set OnceOnly line under the menu does this) and if a choice has already been chosen, it's added to the set and checked before displaying the menu in subsequent tries.

AFAIK, it does not, however, offer the option of making a choice permanent (like your "Leave" choice).

User avatar
Aviala
Miko-Class Veteran
Posts: 530
Joined: Tue Sep 03, 2013 8:40 am
Completed: Your Royal Gayness, Our War Everlasting, Love Bug
Organization: Lizard Hazard Games
Tumblr: lizardhazardgames
itch: aviala
Location: Finland
Contact:

Re: Deleting choices automatically after they have been chosen

#7 Post by Aviala » Wed Feb 06, 2019 7:43 am

I tried searching a lot before I came up with my solution and I never encountered the set functionality OTL Well, I need some choices to stay permanently anyway so I guess I'll still use my solution. Good to know about the set functionality for future reference, I might need it for some future project.

Post Reply

Who is online

Users browsing this forum: No registered users