Preventing the Same Selection Across Multiple Choices

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
YourWaifu
Newbie
Posts: 2
Joined: Sat Apr 13, 2019 2:45 am
Projects: Spice Up Your Life!
Contact:

Preventing the Same Selection Across Multiple Choices

#1 Post by YourWaifu »

Hi all! I'm a pretty novice programmer at best, and though I've messed around with python and ren'py before, this is my first real attempt at a game and by far my most ambitious project. Basically, in my game, the player plays as a restaurant owner and can choose one food to put on their menu for Monday-Friday. I want the player to be able to pick it all at once, which I've figured out how to do, but I'm not sure how to make it so the player can only pick each food once across every day. For example, if the player picks coleslaw on Monday, they won't be able to pick coleslaw on Tuesday, Wednesday, Thursday, or Friday. This is so the player has an incentive to learn more recipes and can't just use the same thing over and over again to gain more affection points with certain npcs. I tried to make it work on my own but I wasn't able to get it to work how I wanted. I'm sure its possible but maybe I'm going about it in the wrong way? Thank you guys so much in advance!

Code: Select all

init python:
    unlockedRecipes = [('Omelette'), ('Bitter Melon Stir Fry'), ('Yogurt Parfait'), ('Chili'), ('French Fries'), ('Coleslaw')]
    recipeNumber = len(unlockedRecipes)
    days = [ ('Monday'), ('Tuesday'), ('Wednesday'), ('Thursday'), ('Friday') ]

default foodMenu = {
    'Monday' : 'Omelette',
    'Tuesday' : 'Bitter Melon Stir Fry',
    'Wednesday' : 'Yogurt Parfait',
    'Thursday' : 'Chili',
    'Friday' : 'French Fries'
    }

screen fmenu:
    frame:
        xpadding 10
        ypadding 10
        area (272, 1, 768, 718)


        grid 1 5 xspacing 500:

            for d in days:

                vpgrid:
                    label d
                    cols 6
                    rows recipeNumber
                    spacing 50
                    draggable False
                    mousewheel False
                    yfill True
                    xfill True

                    scrollbars "horizontal"
                    side_ymaximum 125


                    for r in unlockedRecipes:
                        textbutton r action SetDict(foodMenu, d, r)




    textbutton "Confirm" action Return pos (606, 660)

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Preventing the Same Selection Across Multiple Choices

#2 Post by Remix »

for r in [ k for k in unlockedRecipes if k not in foodMenu.values() ]:

Might do it.

You might consider though looking into drag and drop as an alternative way to do the same.
Frameworks & Scriptlets:

YourWaifu
Newbie
Posts: 2
Joined: Sat Apr 13, 2019 2:45 am
Projects: Spice Up Your Life!
Contact:

Re: Preventing the Same Selection Across Multiple Choices

#3 Post by YourWaifu »

Remix wrote: Mon Apr 15, 2019 4:43 am for r in [ k for k in unlockedRecipes if k not in foodMenu.values() ]:

Might do it.

You might consider though looking into drag and drop as an alternative way to do the same.
That helped a lot, thanks! The only problem is that now it's only showing up with one button for each day that changes to a different food item when its clicked instead of a button for each food item? Would there be anyway to do that?

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Preventing the Same Selection Across Multiple Choices

#4 Post by Remix »

Code: Select all

                    for r in unlockedRecipes:
                        textbutton r:
                            sensitive ( r not in foodMenu.values() )
                            action SetDict(foodMenu, d, r)
Maybe
Frameworks & Scriptlets:

Post Reply

Who is online

Users browsing this forum: Google [Bot]