[solved] Drag and drop placement detection problems for 1 piece puzzle

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
ComputerArt.Club
Veteran
Posts: 427
Joined: Mon May 22, 2017 8:12 am
Completed: Famous Fables, BoPoMoFo: Learn Chinese, Santa's workshop, Cat's Bath, Computer Art Club
Location: Taiwan
Contact:

[solved] Drag and drop placement detection problems for 1 piece puzzle

#1 Post by ComputerArt.Club »

I am experimenting with drag and drop as I hope to use it in my current game but I have not had any success getting it to detect correct placement. I can drag the object but placing it in the correct place is not returning to the game. There is only one piece and one destination for this first test, most my game examples will be simple like this.

From screens:

Code: Select all

screen clock:
    add "clock_screen.png"
    draggroup:
        drag: #puzzle piece
            drag_name "clockhand"
            child "clockhand.png"
            droppable False
            xpos 100 ypos 100
        
        drag:  #destination      
            drag_name "destination"
            child "circle2.png" #same dimensions as clockhand.png
            draggable False
            xpos 880 ypos 633
I also tried:

Code: Select all

screen clock:
    add "clock_screen.png"
    draggroup:
        drag:
            drag_name "clockhand"
            child "clockhand.png"
            droppable False
            draggable True
            xpos 100 ypos 100
        
        drag:        
            drag_name "destination"
            child "circle2.png"
            draggable False
            droppable True
            xpos 880 ypos 633
and, presumably this is the codethat handles detection, pre-game (I tried both of these examples):

Code: Select all

init python:
#modified from cookbook
    def clockhand_dragged(drags, drop):

        if not drop:
            return
and (currently commented)

Code: Select all

#modified from forums
init python:
    def clockhand_dragged(drags, drop):
        if drop:
            drags[0].snap(drop.x,drop.y)
            return
and calling the screen

Code: Select all

    "What time is it now?"
    call screen clock
label afterclock:
    "blah blah blah"
I've checked out a bunch of tutorials and the puzzle demo games, this example is a lot simpler but I am still having trouble with it. :'(

I can move the puzzle piece, but there is no snapping and it does not return to the story.
Last edited by ComputerArt.Club on Tue Jan 22, 2019 12:00 pm, edited 2 times in total.

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

Re: Drag and drop placement detection problems for 1 piece puzzle

#2 Post by Alex »

Yes, 'cause you didn't use your clockhand_dragged function for dragged property of a puzzle piece (see the sample with detectives) - https://www.renpy.org/doc/html/drag_drop.html#examples
Also function must return True somehow to end player's interaction.

User avatar
ComputerArt.Club
Veteran
Posts: 427
Joined: Mon May 22, 2017 8:12 am
Completed: Famous Fables, BoPoMoFo: Learn Chinese, Santa's workshop, Cat's Bath, Computer Art Club
Location: Taiwan
Contact:

Re: Drag and drop placement detection problems for 1 piece puzzle

#3 Post by ComputerArt.Club »

Alex wrote: Mon Jan 21, 2019 2:33 pm Yes, 'cause you didn't use your clockhand_dragged function for dragged property of a puzzle piece (see the sample with detectives) - https://www.renpy.org/doc/html/drag_drop.html#examples
Also function must return True somehow to end player's interaction.
Thanks for your time and your reply. I've added the clockhand_dragged function as a property now:

Code: Select all

screen clock:
    add "clock_screen.png"
    draggroup:
        drag:
            drag_name "clockhand"
            child "clockhand.png"
            dragged "clockhand_dragged" # <---------here
            droppable False
            draggable True
            xpos 100 ypos 100
        
        drag:        
            drag_name "destination"
            child "clockhand.png" #"circle2.png"
            draggable False
            droppable True
            xpos 880 ypos 633

Now it seems to be snapping but I am getting an error:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/aesop script.rpy", line 361, in script
    t "blah blah blah"
  File "renpy/common/000statements.rpy", line 519, in execute_call_screen
    store._return = renpy.call_screen(name, *args, **kwargs)
TypeError: 'unicode' object is not callable
Line 361 is the line before the screen clock is called. I'm guessing it is because it is not terminating the screen properly and the screen has nothing to do now?

Update: actually, I have tried a few more times, and I get the error no matter where I drop the dragged object, not just if I drop it on the destination. :/
Full traceback below.

Tried changing the python code a few different times:

Code: Select all

init python:

    def clockhand_dragged(drags, drop):

        if drop:
            return

Code: Select all

init python:

    def clockhand_dragged(drags, drop):

        if not drop:
            return
            
        store.clockhand_dragged = drags[0].drag_name
        return True

Code: Select all

init python:
    def clockhand_dragged(drags, drop):
        if drop:
            drags[0].snap(drop.x,drop.y)
            return

Code: Select all

init python:
    def clockhand_dragged(drags, drop):
        if drop:
            drags[0].snap(drop.x,drop.y)
            renpy.jump ('afterclock')
No success. The detectives example wants to store those values and use them in text. Here I just want the player to drag the piece to the only possible destination. Any idea what this true statement might look like? Does it actually need return true or is return sufficient in this case (since there is only one possible answer and no wrong answers)?

Perhaps at a later stage similar screens might want to drag to the correct destination or their might be multiple pieces (only one correct). But I suppose I better not get ahead of myself. :P

Thanks for your time!

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/test script.rpy", line 361, in script
    t "blah"
  File "renpy/common/000statements.rpy", line 519, in execute_call_screen
    store._return = renpy.call_screen(name, *args, **kwargs)
TypeError: 'unicode' object is not callable

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "game/test script.rpy", line 361, in script
    t "blah"
  File "X:\games\renpy\renpy-7.1.3-sdk\renpy\ast.py", line 1861, in execute
    self.call("execute")
  File "X:\games\renpy\renpy-7.1.3-sdk\renpy\ast.py", line 1849, in call
    return renpy.statements.call(method, parsed, *args, **kwargs)
  File "X:\games\renpy\renpy-7.1.3-sdk\renpy\statements.py", line 203, in call
    return method(parsed, *args, **kwargs)
  File "renpy/common/000statements.rpy", line 519, in execute_call_screen
    store._return = renpy.call_screen(name, *args, **kwargs)
  File "X:\games\renpy\renpy-7.1.3-sdk\renpy\exports.py", line 2755, in call_screen
    rv = renpy.ui.interact(mouse="screen", type="screen", roll_forward=roll_forward)
  File "X:\games\renpy\renpy-7.1.3-sdk\renpy\ui.py", line 289, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "X:\games\renpy\renpy-7.1.3-sdk\renpy\display\core.py", line 2672, in interact
    repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, **kwargs)
  File "X:\games\renpy\renpy-7.1.3-sdk\renpy\display\core.py", line 3477, in interact_core
    rv = root_widget.event(ev, x, y, 0)
  File "X:\games\renpy\renpy-7.1.3-sdk\renpy\display\layout.py", line 998, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "X:\games\renpy\renpy-7.1.3-sdk\renpy\display\layout.py", line 998, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "X:\games\renpy\renpy-7.1.3-sdk\renpy\display\layout.py", line 998, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "X:\games\renpy\renpy-7.1.3-sdk\renpy\display\screen.py", line 697, in event
    rv = self.child.event(ev, x, y, st)
  File "X:\games\renpy\renpy-7.1.3-sdk\renpy\display\layout.py", line 998, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "X:\games\renpy\renpy-7.1.3-sdk\renpy\display\dragdrop.py", line 816, in event
    return super(DragGroup, self).event(ev, x, y, st)
  File "X:\games\renpy\renpy-7.1.3-sdk\renpy\display\layout.py", line 998, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "X:\games\renpy\renpy-7.1.3-sdk\renpy\display\dragdrop.py", line 706, in event
    rv = run(drag.dragged, joined, drop)
  File "X:\games\renpy\renpy-7.1.3-sdk\renpy\display\behavior.py", line 315, in run
    return action(*args, **kwargs)
TypeError: 'unicode' object is not callable

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

Re: Drag and drop placement detection problems for 1 piece puzzle

#4 Post by Alex »

Code: Select all

init python:

    def clockhand_dragged(drags, drop):

        if not drop:
            return
            
        return True
should work, but use this function without quotes

Code: Select all

dragged clockhand_dragged # <---------here

User avatar
ComputerArt.Club
Veteran
Posts: 427
Joined: Mon May 22, 2017 8:12 am
Completed: Famous Fables, BoPoMoFo: Learn Chinese, Santa's workshop, Cat's Bath, Computer Art Club
Location: Taiwan
Contact:

Re: [solved] Drag and drop placement detection problems for 1 piece puzzle

#5 Post by ComputerArt.Club »

Wow! That fixed it! It was those pesky quotation marks again! Thank you almighty Alex. Your keen eye has solved another problem for me, along with all the other problems that I have searched for on the forums and seen your solutions for.

Also adapted this and used it for another drag and drop style question and it worked as well.

Thanks once again! I will try to check more carefully in future.

Post Reply

Who is online

Users browsing this forum: barsunduk, Google [Bot]