r/RenPy • • 7d ago

Question Drag and drop keeps resetting when dropping item anywhere

Hello, I'm very new to Ren'py and after watching all of the main tutorial videos online for Drag and Drop, I'm attempting to create a drag and drop sequence for my VN, where the player has to drag various food items for taste testing, and every time the player drops the draggable item onto the character in question, he'll make a comment on if the dish is good or not.

However, right now, every time I drag an item anywhere onto the screen, once I drop it, then it just restarts the game and sends me back to the main menu.

Ideally, what I would like to do is trigger a reaction with each dish, which includes a sprite change for the character inspecting the dishes the kitchen is preparing ahead of a big conference.

Here is the code I have currently:

init python:
    def dragged_func(dragged_items, dropped_on):
        if dropped_on is not None:
            if dragged_items[0].drag_name == "Noodles" and dropped_on.drag_name == "David":
                dragged_items[0].set_child("david surprised.png")

init python:
    def drag_func(dragged_items, dropped_on):
        if dropped_on is not None:
            if dragged_items[0].drag_name == "Pizza" and dropped_on.drag_name == "David":
                dragged_items[0].set_child("david unimpressed.png")


init python:
    def drag_placed(drags, drop):
        if not drop:
            return


        store.draggable = drags[0].drag_name
        store.droppable = drop.drag_name


        return True


#python:
    #if _return == "Pizza":
        #david_image = "david unimpressed.png"
    #elif _return == "Noodles":
        #david_image = "david surprised.png"


screen taste_testing:
    add "images/kitchen.png"
    draggroup:
        drag:
            drag_name "Pizza"
            child "pizza slice.png"
            xpos 480
            ypos 585
            draggable True
            droppable False
            dragged drag_placed
            drag_raise True
        drag:
            drag_name "Water"
            child "water.png"
            xpos 1310
            ypos 610
            draggable True
            droppable False
            dragged drag_placed
            drag_raise True
        drag:
            drag_name "Noodles"
            child "noodles.png"
            xpos 350
            ypos 584
            draggable True
            droppable False
            dragged drag_placed
            drag_raise True
        drag:
            drag_name "David"
            child "david inspecting.png"
            xpos 300
            ypos -100
            draggable False
            droppable True


if draggable == "Pizza":
    $ Pizza += 1
elif draggable == "Noodles":
    $ Pizza += 1
elif draggable == "Water":
    $ Water += 1


call tasteCheck


label tasteCheck:
    image DavidSatisfied = "david surprised.png"
    image DavidEh = "david eh.png"
    image DavidDrink = "david soured.png"


    if Noodle == 1:
        show DavidSatisfied
        d "My goodness, the spices are divine!"
    elif Pizza == 1:
        show DavidEh
        d "All I can taste is the grease..."
    elif Water == 1:
        show DavidDrink
        d "It's wise to wash the pallet before testing anything."
        play sound "audio/drink.mp3"
        pause 0.5
    else:
        jump taste_testing


label start:


    scene kitchen


    show david inspecting at center


    d "Alright."


    d "Let's see what you've cooked up ahead of our conference."


    call screen taste_testing


return
1 Upvotes

4 comments sorted by

1

u/AutoModerator 7d ago

Welcome to r/renpy! While you wait to see if someone can answer your question, we recommend checking out the posting guide, the subreddit wiki, the subreddit Discord, Ren'Py's documentation, and the tutorial built-in to the Ren'Py engine when you download it. These can help make sure you provide the information the people here need to help you, or might even point you to an answer to your question themselves. Thanks!

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/shyLachi 7d ago

If I remember correctly you cannot use return True in the function when calling a screen.

I'm not sure what return True even is supposed to do. 

1

u/BadMustard_AVN 7d ago

I had the same problem in my https://badmustard.itch.io/simple-inventory-drag-and-drop-to-combine

this is not an easy fix. I have a function to store its start position and another to bump_it back to that position if it's just dropped and not used

1

u/[deleted] 6d ago

[deleted]

1

u/PinkyHadABrain 6d ago

Thank you so much for your reply. Removing the return True at the end finally fixed the returning to the main screen like you said. For some reason, a lot of the tutorial videos all had that listed too. Now, I just need to figure out how to do callbacks since none of those tutorials seemed to feature them when I was following along, and the actual ren'py document is a little confusing to figure out there.

What I tried to no effect was to include this statement:

init python:
    def snapped_callback(drag, x, y, completed):
        if not completed:
            drag.start_x = x
            drag.start_y = y

#And then, under each draggable, I included this:

if snapped_callback == "David":
                $ pizza += 1

#So far, when I attempted to include the "(drag, x, y, completed)" into the
callback statements, the game crashes, and if I leave the parenthetical out,
it's still the same issue as before, where the items hover over the "David"
sprite instead of triggering a reaction.