Need to Check for Correct Drag&Drop Positions

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
PastelTsundere
Newbie
Posts: 3
Joined: Wed Jan 19, 2022 9:39 pm
Contact:

Need to Check for Correct Drag&Drop Positions

#1 Post by PastelTsundere »

Trying to make sudoku and I'm toying with the idea of drag&drop since I'm only doing numbers 1-4 and having 7 spots to figure out. The actual dragging and dropping is working perfectly but the next part isn't going well. I need the code to be able to check the locations of all the dragged pieces at once, THEN determine if it's right or wrong. I tried looping with "while" but somehow the code makes sudoku=4 and correct_sudoku=4 when i only drag one object to the correct location. If I take the if statements out of the loop then it will only check one before moving onto the next screen, ignoring the rest.

Code: Select all

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

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

        return True
       
default correct_sudoku = 0
default wrong_sudoku = 0
default sudoku = 0     

screen dragtesting:
    draggroup:
        drag:
            drag_name "CircleOne"
            xpos 100
            ypos 100
            child "hover.png"
            draggable False
            droppable True
        drag:
            drag_name "CircleTwo"
            xpos 300
            ypos 100
            child "idle.png"
            draggable False
            droppable True
        drag:
            drag_name "CircleThree"
            xpos 500
            ypos 100
            child "hover.png"
            draggable False
            droppable True
        drag:
            drag_name "CircleFour"
            xpos 700
            ypos 100
            child "idle.png"
            draggable False
            droppable True
        drag:
            drag_name "CircleFive"
            xpos 900
            ypos 100
            child "hover.png"
            draggable False
            droppable True
        drag:
            drag_name "BoxOne"
            xpos 0.25
            ypos 0.25
            drag_raise True
            draggable True
            dragged drag_placed
            droppable False
            frame:
                xpadding 20
                ypadding 20
                text "DragOne"
        drag:
            drag_name "BoxTwo"
            xpos 0.5
            ypos 0.25
            drag_raise True
            draggable True
            dragged drag_placed
            droppable False
            frame:
                xpadding 20
                ypadding 20
                text "DragOne"
        drag:
            drag_name "BoxThree"
            xpos 0.75
            ypos 0.25
            drag_raise True
            draggable True
            dragged drag_placed
            droppable False
            frame:
                xpadding 20
                ypadding 20
                text "DragThree"
        drag:
            drag_name "BoxFour"
            xpos 0.65
            ypos 0.25
            drag_raise True
            draggable True
            dragged drag_placed
            droppable False
            frame:
                xpadding 20
                ypadding 20
                text "DragFour"
        drag:
            drag_name "BoxFive"
            xpos 0.95
            ypos 0.25
            drag_raise True
            draggable True
            dragged drag_placed
            droppable False
            frame:
                xpadding 20
                ypadding 20
                text "DragFive"


label start:
    call screen dragtesting

    $ SudokuTime = True

    while SudokuTime:
        if draggable == "BoxOne" or "BoxTwo" and droppable == "CircleOne":
            $ correct_sudoku += 1
            $ sudoku += 1
        if draggable == "BoxThree" and droppable == "CircleTwo":
            $ correct_sudoku += 1
            $ sudoku += 1
        if draggable == "BoxFour" and droppable == "CircleThree":
            $ correct_sudoku += 1
            $ sudoku += 1
        if draggable == "BoxFive" and droppable == "Circle Four":
            $ correct_sudoku += 1
            $ sudoku += 1
        if sudoku == 4:
            jump checkit

label checkit:
    if correct_sudoku == 4:
        "you did it"
    else:
        "try again"
        $ wrong_sudoku += 1
        jump start

Post Reply

Who is online

Users browsing this forum: Google [Bot]