Drag and Drop with multiple Drops and conditionals

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
Alexis_Royce
Regular
Posts: 39
Joined: Tue Apr 10, 2012 2:34 pm
Projects: May I Take Your Order
Organization: imagiBROS
Tumblr: alexis_royce
Deviantart: alexisroyce
itch: alexisroyce
Contact:

Drag and Drop with multiple Drops and conditionals

#1 Post by Alexis_Royce » Mon Oct 19, 2020 12:14 pm

Hello! I’ve been plugging away at a drag and drop mechanic for the past couple weeks. While I’ve learned a heck of a lot more about how python works, I’m still falling short of what I need to make all this work.

I’m making a game about serving food to customers, and there’s a light puzzle mechanic involved with serving the right foods. I’d like for the player to be able to drag a food icon to either dish drag(droppable), and for the program to wait for both dishes to be full, at which point the player can click a button to accept the choice. Only when the button is clicked would I want the data of which food went into which dish to be stored, and for the game to proceed. I’d also like for players to be able to pick the food icons back up off the plates, if the button hasn’t been clicked yet. In case they want to change their minds. I'd use the variables of which food was in which dish to determine future plot and whatnot.

Currently, my code doesn’t want to wait, and moves on when any food is dropped into any dish. I’m only able to make the code store the names of one dish and one food. I’ve tried looking at the card game examples, and I also tried to start from scratch and implement something using this very cool-looking coding instead. It has a wonderful snapping-back function, and would not proceed, but I lost some hovering functionality in my drags, and couldn't figure out where any drag variables were being stored.

So here’s my current code for the serving mechanic:

Code: Select all

#####################################################################
# Orig Attempt                                                   ####
#####################################################################
scene tmeal with fade
init python:

    def fud_dragged(drags, drop):

        if not drop:
            return

        store.fud = drags[0].drag_name
        store.plate = drop.drag_name

        store.fud2 = drags[0].drag_name
        store.plate2 = drop.drag_name

        #if
        return True


screen tsend_fud_screen:
    add "tmeal.png"


    draggroup:
############## FOODS    ###############
        drag:
            drag_name "Steak"
            child "steak.png"
            droppable False
            dragged fud_dragged
            hovered Show("thap")
            unhovered Hide("thap")
            alt "A delicious, rare steak."
            xpos 800 ypos 200
        drag:
            drag_name "Salad"
            child "salad.png"
            droppable False
            dragged fud_dragged
            hovered Show("tmad")
            unhovered Hide("tmad")
            alt "A leafy green salad."
            xpos 1000 ypos 280

############# DISHES ####################
        drag:
            drag_name "Dish1"
            child "dish.png"
            draggable False
            xpos 203 ypos 285

        drag:
            drag_name "Dish2"
            child "dish.png"
            draggable False
            xpos 603 ypos 385

##### This is a little frown face that shows up on top of a character's face when the salad is hovered over.
screen tmad:

    add "mad.png" xpos 9 ypos 255

#### This is a little happy face that shows up on top of a character's face when the steak is hovered over.
screen thap:

    add "happy.png" xpos 9 ypos 280

#### This is a placeholder for a textbox to pop up and show a description of food when the food is hovered over. Currently doesn't show.
screen des:

    add "descriptionbox.png" xpos 9 ypos 900

label tsend_fud:
    "Drag and drop the food from your imagination to the serving dish!"
    ### Display Proceed button
    $ proceed = "true"
    call screen tsend_fud_screen

label check_fud:
    #### Blah blah blah game continues below ###

And here’s my current code for the button to proceed. I’ve got it crammed into the quick menu:

Code: Select all

        hbox:
            style_prefix "quick"

            xalign 0.9
            yalign .9

            if proceed == "true":
                imagebutton:
                    idle "sw1.png"
                    hover "sw2.png"
                    insensitive "swg.png"
                    #### I'm trying to gray out the button if both dishes are not filled. I was thinking about just making it check both dish variables, and if both are still the default, the button won't work.
                    sensitive "store.fud" != "drags[0].drag_name"
                    action Confirm("Serve this food?", yes=Call("check_fud"), no=None, confirm_selected=False)
                    alt "Proceed?"
If anyone could assist me with this, I'd be very grateful!
Image

User avatar
Alex
Lemma-Class Veteran
Posts: 2981
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Drag and Drop with multiple Drops and conditionals

#2 Post by Alex » Mon Oct 19, 2020 1:50 pm


Post Reply

Who is online

Users browsing this forum: Bing [Bot], GetOutOfMyLab, mold.FF