Checking number of options selected in a check menu [Solved]

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
Matalla
Veteran
Posts: 202
Joined: Wed Mar 06, 2019 6:22 pm
Completed: Max Power and the Egyptian Beetle Case, The Candidate, The Last Hope, El cajón del viejo escritorio, Clementina y la luna roja, Caught in Orbit, Dirty Business Ep 0, Medianoche de nuevo, The Lost Smile
itch: matalla-interactive
Location: Spain
Contact:

Checking number of options selected in a check menu [Solved]

#1 Post by Matalla »

I am doing a little something that I thought it would be pretty easy, but it's giving me all kinds of silly problems.

I have a screen where clues discovered through the game appear (it would appear ones or others, depending on the player choices). At some point, it would be possible to solve a mistery combining certain clues (or not solve it, if the conclusions are not the right ones, leading to a different ending). What I want is:

- When the player select 2 clues, check if those 2 clues have a valid conclusion
- If they have it, the proper deduction appear on the right page and are removed from the left page.

So far I have, more or less, acomplished this. If 2 choices with a valid conclusion are selected, they dissapear and the proper conclusion appear in the right column.

Screen with all clues discovered at a certain point:
Image

Screen when selected 2 certain clues with a valid deduction:
Image

This is, more or less, the code:

Code: Select all

screen deductions ():
    
    if clue1 == True and clue4 == True and finalclue1 == False:
        $ finalclue1 = True
    # More pairs conditions here
    
    hbox:
        vbox:
            
            label _("CLUES")
            
            if event1 == True and finalclue1 == False:
                textbutton _("- A clue"):
                    action ToggleVariable("clue1", true_value=True, false_value=False)
                    selected clue1 == True
            if questionhusband == "option1":
                textbutton _("- A clue"):
                    action ToggleVariable("clue2", true_value=True, false_value=False)
                    selected clue2 == True
            elif questionhusband == "option2":
                textbutton _("- A clue"):
                    action ToggleVariable("clue3", true_value=True, false_value=False)
                    selected clue3 == True
            if photocomment == "option1" and finalclue1 == False:
                textbutton _("- A clue"):
                    action ToggleVariable("clue4", true_value=True, false_value=False)
                    selected clue4 == True
            elif photocomment == "option2":
                textbutton _("- A clue"):
                    action ToggleVariable("clue5", true_value=True, false_value=False)
                    selected clue5 == True
            if phonecall1 == True:
                textbutton _("- A clue"):
                    action ToggleVariable("clue6", true_value=True, false_value=False)
                    selected clue6 == True
            # Etc.
            
        vbox:
            
            label "DEDUCTIONS"

            if finalclue1 == True:
                text _("- I think this happened")
But I want to make the check everytime any 2 choices are selected, whether or not they have a conclusion. If they have no conclusion, all options are deselected. Additionally, I would like to add a counter; anytime a pair is selected (doesn't matter if they are a valid pair or not), a counter increases. If the counter reaches a certain number, no further deductions can be done.

Any suggestion on how to handle this?
Last edited by Matalla on Tue Apr 23, 2019 2:05 pm, edited 1 time in total.
Comunidad Ren'Py en español (Discord)
Honest Critique

User avatar
Per K Grok
Miko-Class Veteran
Posts: 882
Joined: Fri May 18, 2018 1:02 am
Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1-3, the Phantom Flyer
itch: per-k-grok
Location: Sverige
Contact:

Re: Checking number of options selected in a check menu

#2 Post by Per K Grok »

Matalla wrote: Sat Apr 20, 2019 11:47 pm I am doing a little something that I thought it would be pretty easy, but it's giving me all kinds of silly problems.

-----

But I want to make the check everytime any 2 choices are selected, whether or not they have a conclusion. If they have no conclusion, all options are deselected. Additionally, I would like to add a counter; anytime a pair is selected (doesn't matter if they are a valid pair or not), a counter increases. If the counter reaches a certain number, no further deductions can be done.

Any suggestion on how to handle this?

Maybe you could do something like this.

one variable for the number of selected choices, default 0
one variable for number of tries, starting at 0
one list for selected choices, starting empty
one function to check if selected choices match

When a choice is picked
* +1 to the variable for the number of selected choices
* add the number of the choice to the list

when number of selected choices hits 2
* +1 to the number of tries
* check if selected choices from the list match
** if so make the necessary changes
* remove items from the list

User avatar
Matalla
Veteran
Posts: 202
Joined: Wed Mar 06, 2019 6:22 pm
Completed: Max Power and the Egyptian Beetle Case, The Candidate, The Last Hope, El cajón del viejo escritorio, Clementina y la luna roja, Caught in Orbit, Dirty Business Ep 0, Medianoche de nuevo, The Lost Smile
itch: matalla-interactive
Location: Spain
Contact:

Re: Checking number of options selected in a check menu

#3 Post by Matalla »

These are good ideas. I tried to use a variable to keep tracking of the number of choices selected at a given time, but is more complicated and confusing than adding 1 to that variable, you'd also have to substract 1 if the option is deselected, otherwise just selecting and deselecting one single option would increase the variable, and I haven't found a way to do that.

The counter of pair tries I supose it would be trivial once I find a way of doing this right.

For the rest, I'm not very good with lists, but I think I could manage if I understand what's the goal, but I have absolutely no idea about functions. Is it necessary for what you suggested to work? I can do the checking hardcoding the conditions like in the example shown...

I actually made a small progress using a list for the checking counter, but I still have problems emptying the list. Otherwise, it seems to keep track of options selected.

Code: Select all

    $ clueschecked = len(clueslist)
    
    if clueschecked == 2:
        if (clueslist == ["clue1", "clue4"] or clueslist == ["clue4", "clue1"]) and finalclue1 == False:
            $ finalclue1 = True

Code: Select all

            if event1 == True and finalclue1 == False:
                textbutton _("- A clue"):
                    action ToggleSetMembership(clueslist, "clue1")
            # Etc.        
Comunidad Ren'Py en español (Discord)
Honest Critique

User avatar
Per K Grok
Miko-Class Veteran
Posts: 882
Joined: Fri May 18, 2018 1:02 am
Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1-3, the Phantom Flyer
itch: per-k-grok
Location: Sverige
Contact:

Re: Checking number of options selected in a check menu

#4 Post by Per K Grok »

Matalla wrote: Sun Apr 21, 2019 10:49 am These are good ideas. I tried to use a variable to keep tracking of the number of choices selected at a given time, but is more complicated and confusing than adding 1 to that variable, you'd also have to substract 1 if the option is deselected, otherwise just selecting and deselecting one single option would increase the variable, and I haven't found a way to do that.

The counter of pair tries I supose it would be trivial once I find a way of doing this right.

For the rest, I'm not very good with lists, but I think I could manage if I understand what's the goal, but I have absolutely no idea about functions. Is it necessary for what you suggested to work? I can do the checking hardcoding the conditions like in the example shown...

I actually made a small progress using a list for the checking counter, but I still have problems emptying the list. Otherwise, it seems to keep track of options selected.

Code: Select all

    $ clueschecked = len(clueslist)
    
    if clueschecked == 2:
        if (clueslist == ["clue1", "clue4"] or clueslist == ["clue4", "clue1"]) and finalclue1 == False:
            $ finalclue1 = True

Code: Select all

            if event1 == True and finalclue1 == False:
                textbutton _("- A clue"):
                    action ToggleSetMembership(clueslist, "clue1")
            # Etc.        
OK, I did not think about the possibility to deselect a choice.

Perhaps it would be easier just to go through the available choices and count how may are True.

A list is not necessary, you could just have two variables, i.e. clueA and clueB.

You could then do something like this.

Code: Select all

if clue1==True:
    cluecounter +=1
    if clueA==0:
        $ clueA=1
    else:                ######
        $ clueB=1    ###### this part not necessary for the first combination since clueA must be 0 at this time.

if clue2==True:
    cluecounter +=1
    if clueA==0:
        $ clueA=2
    else:
        $ clueB=2

---- and so on
and then you could do something like this (when I said function I should probably have said something like functionality)

Code: Select all

if cluecounter==2:
    $ tries +=1 
    if clueA==1 and clueB==4:
          --- do the stuff to be done at a match (included setting clue1 and clue4 to False so that they are not counted next time around)
    elif clueA==3 and clueB==6:
         --- do the stuff to be done at a match
         
  ----------
  
  
$ clueconter=0
$ clueA=0
$ clueB=0

lists are very useful for a lot of things, but are also sensitive when you try to do something outside the range or with an item that is not in the list.
Removing stuff from a list you can do with 'pop' if you want to remove an item at a certain position in the list, or 'remove' if you want to remove an item by name.

User avatar
Matalla
Veteran
Posts: 202
Joined: Wed Mar 06, 2019 6:22 pm
Completed: Max Power and the Egyptian Beetle Case, The Candidate, The Last Hope, El cajón del viejo escritorio, Clementina y la luna roja, Caught in Orbit, Dirty Business Ep 0, Medianoche de nuevo, The Lost Smile
itch: matalla-interactive
Location: Spain
Contact:

Re: Checking number of options selected in a check menu

#5 Post by Matalla »

Nope, I tried that and it doesn't behave like expected at all. It does so many weird things that I don't even know where and how start to fix it.

I'll keep working the list approach and see what I can do. Thanks for your suggestions about that, I tried with pop using a loop but didn't behave as I expected (I didn't try remove except in the cases where there is a match because I don't know the exact items that are in the list). I hope I'll figure it out eventually.
Comunidad Ren'Py en español (Discord)
Honest Critique

User avatar
Per K Grok
Miko-Class Veteran
Posts: 882
Joined: Fri May 18, 2018 1:02 am
Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1-3, the Phantom Flyer
itch: per-k-grok
Location: Sverige
Contact:

Re: Checking number of options selected in a check menu

#6 Post by Per K Grok »

Matalla wrote: Sun Apr 21, 2019 4:45 pm Nope, I tried that and it doesn't behave like expected at all. It does so many weird things that I don't even know where and how start to fix it.

I'll keep working the list approach and see what I can do. Thanks for your suggestions about that, I tried with pop using a loop but didn't behave as I expected (I didn't try remove except in the cases where there is a match because I don't know the exact items that are in the list). I hope I'll figure it out eventually.
This seams to work.
When testing my idea I found that the list part (or two variables) was unnecessary. Trying to set clue1 etc. to False did not function as I thought, so that had to go as well. I added messages when 'no match' or 'too many clues' instead.

Code: Select all

default clue1=False
default clue2=False
default clue3=False
default clue4=False
default clue5=False
default clue6=False

default deduction1=False
default deduction2=False
default deduction3=False

default cluecounter=0
default tomany=False
default nomatch=False

screen deductions ():

    if clue1==True and deduction1==False:
        $ cluecounter +=1
    if clue2==True and deduction2==False:
        $ cluecounter +=1
    if clue3==True and deduction3==False:
        $ cluecounter +=1
    if clue4==True and deduction1==False:
        $ cluecounter +=1
    if clue5==True and deduction2==False:
        $ cluecounter +=1
    if clue6==True and deduction3==False:
        $ cluecounter +=1

    $ nomatch=False

    if cluecounter>2:
        $ tomany=True


    else:
        $ tomany=False

        if cluecounter==2:
            $ nomatch=True

        if clue1==True and clue4==True and deduction1==False:
            $ deduction1=True
            $ nomatch=False

        elif clue2==True and clue5==True and deduction2==False:
            $ deduction2=True
            $ nomatch=False

        elif clue3==True and clue6==True and deduction3==False:
            $ deduction3=True
            $ nomatch=False

    $ cluecounter=0


    hbox:
        vbox:

            label _("CLUES")

            if deduction1==False:
                textbutton _("- A clue 1"):
                    action ToggleVariable("clue1", true_value=True)
                    selected clue1 == True
            if deduction2==False:
                textbutton _("- A clue 2"):
                    action ToggleVariable("clue2", true_value=True)
                    selected clue2 == True
            if deduction3==False:
                textbutton _("- A clue 3"):
                    action ToggleVariable("clue3", true_value=True)
                    selected clue3 == True
            if deduction1==False:
                textbutton _("- A clue 4"):
                    action ToggleVariable("clue4", true_value=True)
                    selected clue4 == True
            if deduction2==False:
                textbutton _("- A clue 5"):
                    action ToggleVariable("clue5", true_value=True)
                    selected clue5 == True
            if deduction3==False:
                textbutton _("- A clue 6"):
                    action ToggleVariable("clue6", true_value=True)
                    selected clue6 == True

            if tomany==True:
                text "Only two clues at a time."
            if nomatch==True:
                text "These clues does not match."


        vbox:

            label "DEDUCTIONS"

            if deduction1 == True:
                text _("- I think this happened 1")
            if deduction2 == True:
                text _("- I think this happened 2")
            if deduction3 == True:
                text _("- I think this happened 3")



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

Re: Checking number of options selected in a check menu

#7 Post by philat »

Eh... there are a lot of ways to do this, but I wouldn't write it out all long hand -- using a list and some predefined objects should be cleaner in the long run (although writing it all out may be simpler if there aren't that many clues). Leaving a comment to remind myself to get back to you in the next 24 hours.

As a data point though how many clues and deductions are you envisioning?

User avatar
Matalla
Veteran
Posts: 202
Joined: Wed Mar 06, 2019 6:22 pm
Completed: Max Power and the Egyptian Beetle Case, The Candidate, The Last Hope, El cajón del viejo escritorio, Clementina y la luna roja, Caught in Orbit, Dirty Business Ep 0, Medianoche de nuevo, The Lost Smile
itch: matalla-interactive
Location: Spain
Contact:

Re: Checking number of options selected in a check menu

#8 Post by Matalla »

Per K Grok wrote: Mon Apr 22, 2019 4:21 am
This seams to work.
When testing my idea I found that the list part (or two variables) was unnecessary. Trying to set clue1 etc. to False did not function as I thought, so that had to go as well. I added messages when 'no match' or 'too many clues' instead.

Code: Select all

...
Thank you Grok, I'll try your code later. I have a working code that does the same thing with messages (ie: these clues match, these clues don't match, need 2 clues, etc.).

Code: Select all

default clueslist = []

screen deductions():
    
    $ clueschecked = len(clueslist)
    
    if clueschecked < 2:
        text "2 clues are needed"
    elif clueschecked == 2:
        if (clueslist == ["clue1", "clue4"] or clueslist == ["clue4", "clue1"]) and finalclue1 == False:
            text "These clues match"
            # Here should be the code to hide clues from the left, show deduction on the right and reset the list
        else:
            text "These clues don't match"
            # Here should be the code to deselect clues and reset the list
    
    hbox:
        vbox:
            label _("CLUES")
            if event1 == True and finalclue1 == False:
                textbutton _("- Clue 1"):
                    action ToggleSetMembership(clueslist, "clue1")
                    selected "clue1" in clueslist
            if questionhusband == "option1":
                textbutton _("- Clue 2"):
                    action ToggleSetMembership(clueslist, "clue2")
                    selected "clue2" in clueslist
            elif questionhusband == "option2":
                textbutton _("- Clue 3"):
                    action ToggleSetMembership(clueslist, "clue3")
                    selected "clue3" in clueslist
            if photocomment == "option1" and finalclue1 == False:
                textbutton _("- Clue 4"):
                    action ToggleSetMembership(clueslist, "clue4")
                    selected "clue4" in clueslist
            # Etc.

        vbox:
            label "DEDUCTIONS"
            if finalclue1 == True:
                text _("- I think this happened 1")
The trouble is, I can't find a way to execute the proper code instead of those messages (deselecting clues, hiding them or showing deductions, etc.). I'll try to mix it up with your code and see how it works. The closest I got to a solution was by calling a label and executing the code there. I don't understand why it can't work inside the screen, must be a silly thing. For what is worth, this is the label's code.

Code: Select all

label checkclues:
    $ triesleft -= 1
    if (clueslist == ["clue1", "clue4"] or clueslist == ["clue4", "clue1"]) and finalclue1 == False:
        python:
            finalclue1 = True
            clueslist = []
    # Check for other matches here
    else:
        python:
            clueslist = []
    return
Anyway, the label method is too clumsy to be used. Too many things are messed up (mainly, it messes with the main narration, advancing the dialogue everytime the label is called and showing it for an ugly split second).
philat wrote: Mon Apr 22, 2019 6:04 am Eh... there are a lot of ways to do this, but I wouldn't write it out all long hand -- using a list and some predefined objects should be cleaner in the long run (although writing it all out may be simpler if there aren't that many clues). Leaving a comment to remind myself to get back to you in the next 24 hours.

As a data point though how many clues and deductions are you envisioning?
Thank you philat, I look forward to your suggestions. Total clues should be around 18 (maybe a little less than half of them available in a particular playthrough, since most of them are mutually exlusive and others depends on certain events), I could add or drop some, but close to that number. Total posible deductions should be around 6.

Although this is an adaptation from a previous work of mine (a movie/animated comic) and I'm sure about the main storyline, I'm working the branches on the fly and the exact numbers may vary slightly, but not very much.
Comunidad Ren'Py en español (Discord)
Honest Critique

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

Re: Checking number of options selected in a check menu

#9 Post by philat »

How you do this is honestly up to you, but this is one way that I would imagine going about it. It may be overkill if the game is simpler, but it would be easier to add/modify clues and deductions on the fly, since all you have to do is create a few new objects and link them together. It's also easy to extend the object as necessary (for instance, you could specify a label name to be stored in each object and call that name when the clue/deduction is found in the .find() method, or you could add a .found attribute to check whether the clue has EVER been found (even if it has been removed from the list of found_clues after being 'used' for the deduction), etc.).

The Deduce screen action is just a custom action; not particularly complicated (you can see examples of other actions in the renpy common files).

Code: Select all

init python:
    class Clue():
        def __init__(self): # initializes empty objects - this is to make it easy to add references between objects
            pass

        def create(self, name):
            self.name = name

        def find(self):
            store.found_clues.append(self)

        def use(self):
            store.found_clues.remove(self)

    class Deduction():
        def __init__(self):
            pass

        def create(self, name, related_clues=[]):
            self.name = name
            self.related_clues = related_clues

        def find(self):
            store.found_deductions.append(self)

    class Deduce(Action):

        def __init__(self, item):
            self.item = item
        
        def __call__(self):
            # toggle membership in list
            if self.item not in store.selected_clues:
                if len(store.selected_clues) < 2: # if already two selected, nothing happens
                    store.selected_clues.append(self.item)
            else:
                store.selected_clues.remove(self.item)

            check_deductions() # run check_deductions function defined below

            renpy.restart_interaction() # restart interaction to refresh the screen

        def get_selected(self):
            return self.item in store.selected_clues

    def check_deductions(): # this runs all possible deductions for a match -- if the game is VERY large it may be less performant but I doubt it matters realistically for a smaller game
        for d in store.all_deductions:
            if d.related_clues and set(d.related_clues) == set(store.selected_clues): # using set() to ignore order (but not to start because I'm lazy and prefer lists
                d.find() # if there's a match, find the deduction
                for c in d.related_clues: # and remove all clues from the found_clues list
                    c.use()
                store.selected_clues = [] # and reset selected_clues

default all_clues = [Clue() for i in range(16)] # creates a list of empty clues and deductions
default all_deductions = [Deduction() for i in range(6)]

default selected_clues = []
default found_clues = []
default found_deductions = []

screen clues_deductions():
    hbox:
        spacing 10

        vbox:
            xsize 350
            label "Clues"
            for clue in found_clues:
                textbutton clue.name action Deduce(clue)
        vbox:
            xsize 350
            label "Deductions"
            for deduction in found_deductions:
                text deduction.name
        vbox:
            xsize 350
            label "Debug"
            if len(selected_clues)==2:
                text "You can only select two clues at a time."

label start:
    "starting test"

label setup:
    python:
        all_clues[0].create("The butler was having an affair with the housekeeper.") # creating actual clues and deductions
        all_clues[1].create("clue2")
        all_clues[2].create("clue3")
        all_clues[3].create("The housekeeper's husband doesn't drink.")
        all_clues[4].create("clue5")
        all_clues[5].create("clue6")

        all_deductions[0].create("The butler did it!", [all_clues[0], all_clues[3]])
        all_deductions[1].create("deduction2", [all_clues[1], all_clues[5]])
        all_deductions[2].create("deduction3", [all_clues[2], all_clues[4]])
        all_deductions[3].create("deduction4")
        all_deductions[4].create("deduction5")
        all_deductions[5].create("deduction6")

        # obviously create more clues / populate deductions as necessary

label running_test:
    show screen clues_deductions
    "I have no clues."
    $ all_clues[0].find()
    $ all_clues[1].find()
    "I found some clues."
    $ all_clues[2].find()
    $ all_clues[3].find()
    "I found more clues."
    $ all_clues[4].find()
    $ all_clues[5].find()
    "All available clues found."
    pause

User avatar
Matalla
Veteran
Posts: 202
Joined: Wed Mar 06, 2019 6:22 pm
Completed: Max Power and the Egyptian Beetle Case, The Candidate, The Last Hope, El cajón del viejo escritorio, Clementina y la luna roja, Caught in Orbit, Dirty Business Ep 0, Medianoche de nuevo, The Lost Smile
itch: matalla-interactive
Location: Spain
Contact:

Re: Checking number of options selected in a check menu

#10 Post by Matalla »

Per K Grok wrote: Mon Apr 22, 2019 4:21 am ...
Grok, I checked your code and works very similar to the one I had. It manages well the basic logic of the issue, but I still have the same problems to manage the number of clues selected, etc. It has been very instructive to see how you approach the problem, though, and I thank you for that (and your time, of course)
philat wrote: Mon Apr 22, 2019 10:41 pm ...
Philat, I have to say that, although I didn't understand a bit of that, it's certainly fascinating.

Let me say it again:
Image

And, even if I didn't understand a word (or a function in this case), I feel strangely confident in the crazy believe that I can implement it without (much) difficulty... And even understand most of it in the process! If I manage to do it and finally use it, I'll credit you for that fine piece of code-art, of course.

Just to be clear, I should run the contents of the label setup at start to create all clues and deductions and then in every part of the game when a clue is found the "all_clues[x].find()" bit, right? And how I should reference the text of the found clues or deductions for using in other screens or labels? After a quick look, I believe I could find the way to show the related text of a particular clue or deduction.

But, I'm not so sure how to do it only with the found ones, or how to use the deductions found in conditionals to determine the outcome.

Code: Select all

if deduction(x) in found_deductions:
	d "I found that [deduction(x)]"
	jump endingx
	
??

Well, anyway I'm going to start trading punches with this beast of yours and feel its fangs deep in my flesh... See you...

... And don't get me started with the freaking butlers! I always hated those... beings... And I can prove it!
https://www.youtube.com/watch?v=GfC-YFrhjpA
Comunidad Ren'Py en español (Discord)
Honest Critique

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

Re: Checking number of options selected in a check menu

#11 Post by philat »

You can just refer to each clue by its index in the all_clues or all_deductions list (refer to all_clues[0].create("The butler was having an affair with the housekeeper.") ). You could also manually assign more convenient names for them, but I didn't, because I'm lazy. It's not very different from using clue1, clue2, etc.

For instance, checking whether you have the deduction for "The butler did it" would be:

Code: Select all

if all_deductions[0] in found_deductions: # if the Deduction object at all_deductions[0] (which we initialized with  // all_deductions[0].create("The butler did it!", [all_clues[0], all_clues[3]]) // ) is in the list found_deductions
    "I found [all_deductions[0].name]." # obviously there is a capitalization issue here, but that's for smoothing out later
As noted above, you could also extend the Deduction object to have a .found attribute that turns to True when you use the .find() method, so you could just write if all_deductions[0].found: -- again, up to your taste.

User avatar
Matalla
Veteran
Posts: 202
Joined: Wed Mar 06, 2019 6:22 pm
Completed: Max Power and the Egyptian Beetle Case, The Candidate, The Last Hope, El cajón del viejo escritorio, Clementina y la luna roja, Caught in Orbit, Dirty Business Ep 0, Medianoche de nuevo, The Lost Smile
itch: matalla-interactive
Location: Spain
Contact:

Re: Checking number of options selected in a check menu

#12 Post by Matalla »

I just finalized setting up the whole thing and it works nicely. Thank you very much, philat!

I added a new action (probably could have done better, but it works) to deselect the clues when they don't match and implemented a counter

Code: Select all

    class Failed(Action):

        def __init__(self, item):
            self.item = item
        
        def __call__(self):
            store.selected_clues = []

            renpy.restart_interaction() 

    def check_deductions(): 
        for d in store.all_deductions:
            # using set() to ignore order (but not to start because I'm lazy and prefer lists
            if d.related_clues and set(d.related_clues) == set(store.selected_clues):
                d.find() # if there's a match, find the deduction
                for c in d.related_clues: # and remove all clues from the found_clues list
                    c.use()
                store.selected_clues = [] # and reset selected_clues
                store.triesleft -= 1 # 1 try less

Put this in the deduction screen instead of the warning about the selected clues.

Code: Select all

                if triesleft < 1:
                    text _("I can't waste more time with this")
                if len(selected_clues)==2:
                    timer 0.1 action Show("messageclues")

The screen for the message when clues don't match

Code: Select all

screen messageclues():
    
    modal True
    
    zorder 101
    
    frame:
        xalign 0.5
        yalign 0.5
        padding (20, 20)
        xmaximum 450
        ymaximum 250
        vbox:
            text _("I can't get anything out of this clues")
            textbutton _("Keep trying"):
                action [Failed(selected_clues), SetVariable("triesleft", triesleft-1), Hide ("messageclues")]
Also modified slightly the clue buttons to get them inactive when the limit of tries has been reached

Code: Select all

textbutton "- " + clue.name action [Deduce(clue), SensitiveIf(triesleft>0)]
Comunidad Ren'Py en español (Discord)
Honest Critique

Post Reply

Who is online

Users browsing this forum: Google [Bot]