Page 1 of 1

Deleting choices automatically after they have been chosen

Posted: Wed Jan 16, 2019 7:51 am
by Aviala
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.

Re: Deleting choices automatically after they have been chosen

Posted: Thu Jan 31, 2019 7:13 pm
by wyverngem
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.

Re: Deleting choices automatically after they have been chosen

Posted: Sat Feb 02, 2019 4:22 am
by Aviala
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.

Re: Deleting choices automatically after they have been chosen

Posted: Sat Feb 02, 2019 2:03 pm
by AON
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"

Re: Deleting choices automatically after they have been chosen

Posted: Tue Feb 05, 2019 8:45 am
by Aviala
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"

Re: Deleting choices automatically after they have been chosen

Posted: Wed Feb 06, 2019 5:21 am
by philat
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).

Re: Deleting choices automatically after they have been chosen

Posted: Wed Feb 06, 2019 7:43 am
by Aviala
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.