Drag & Drop Question #1: Activating and Deactivating

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
Exiscoming
Regular
Posts: 127
Joined: Tue Apr 29, 2014 5:37 pm
Contact:

Drag & Drop Question #1: Activating and Deactivating

#1 Post by Exiscoming » Tue Sep 13, 2022 9:09 am

I'm experimenting with the Drag & Drop feature, but there's been a bunch of things I haven't been able to figure out.
I'll probably make a few threads about this, but now for my first question:
How to activate and de-activate object?
I want a player to be able to place berries into a bowl.

1. Create both a de-active and active graphic and put those within a layeredimage.
2. Put in the drag & drop code that, when dragging an item, changes its variable from False to True (and vise versa)
3. When a draggable is dropped, the variable should go back to False.

The problem: It works for the berries, but the bowl stays active.

Image
Now I am not quite sure if this is the best way to go about things, but it's the only way I can think of right now.
Is there perhaps a 'hover' state that will change the graphic between active and de-active? Am I on the right track? Should I do it completely differently?
I would really appreciate your thoughts!

Code: Select all

### BOOLS ###
default berriesActive = False
default bowlActive = False

### Berries graphic ###
layeredimage berriesGraphic:
    if berriesActive == False:
        "gui/berries.png"
    else:
        "gui/berries-hover.png"

### Bowl graphic ###
layeredimage bowlGraphic:
    if bowlActive == False:
        "gui/bowl.png"
    else:
        "gui/bowl-hover.png"

init python:
    def ac_me(activated):               # If graphic is activated
        store.berriesActive = True
        store.bowlActive = True
        return

    def drag_placed(drags, drop):       # If graphic is dropped
        store.bowlActive = False		<- ! This does not work !
        store.berriesActive = False
        if not drop:
            return

        store.draggable = drags[0].drag_name

        return True
        
### Screen ###
screen drag_sample:
    draggroup:
        drag:
            drag_name "berries"
            child "berriesGraphic"
            activated ac_me
            xpos 300
            ypos 300
            draggable True
            droppable False
            dragged drag_placed
            drag_raise True
        drag:
            drag_name "The bowl"
            child "bowlGraphic"
            activated ac_me
            xpos 0.4
            ypos 0.35
            draggable False
            droppable True
        
### Call screen ###
label dragNDrop:
    scene black
    call screen drag_sample


Post Reply

Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot]