We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.

Add dragging and methods to a list of objects

Home Forums Puzzles Add dragging and methods to a list of objects

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #26489
    sleaman
    Participant

    So I have a list of objects. I’d like to add drag methods to each of these specific objects, with a generic function on drag drop. I’d like this to be a function so I can add many items without repeating a lot of puzzles.

    I’ve tried running the list through a for loop and assigning the drag functionality to each element, but it applies the drag to the last element in the list. I assume this is because each loop writes over the drag function rather than adds to it…

    What is the best way using puzzles to create the functionality I’m looking for? Or is this something I should make a js function for?

    Thanks!

    #26503

    I’ve tried running the list through a for loop and assigning the drag functionality to each element, but it applies the drag to the last element in the list. I assume this is because each loop writes over the drag function rather than adds to it…

    You’re mostly right. This is a common issue with such puzzles as “when dragged over” being used in a loop.

    You’re probably using the loop’s counter variable to reference objects inside the “move do” or the other slots. It makes “when dragged over” rely on the counter’s value at the moment you start dragging. But the loop is executed immediately and when it’s over its counter’s value equals to the last element.

    In the end you have dragging registered on every object from the list, that’s great, but sadly they all will drag the same object that happened to be the last.

    There’s a standard workaround to deal with this situation. You should extract “when dragged over” puzzle into a separate procedure as follows:
    drag_in_procedure.png

    Attachments:
    You must be logged in to view attached files.

    Co-founder and lead developer at Soft8Soft.

    #27387
    sleaman
    Participant

    Fantastic, thank you very much for explaining :good:

    #29000
    GLiFTeK
    Customer

    There’s a standard workaround to deal with this situation. You should extract “when dragged over” puzzle into a separate procedure as follows: drag_in_procedure.png

    oh man this just got me out of a rut with this issue.

    thanks!

    #46106
    Crunch
    Customer

    blessings be upon you Ivan! that technique was really helpful. Thank u!

    #55454
    kdv
    Participant

    on drag drop

    Note: if you drop two or more objects with the same name only one of them will be draggable. The rename object puzzle is needed.

    Puzzles and JS. Fast and expensive.

    If you don’t see the meaning in something it primarily means that you just don’t see it but not the absence of meaning at all.

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.