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 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #26489
    Avatarsleaman
    Newbie

    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
    Avatarsleaman
    Newbie

    Fantastic, thank you very much for explaining :good:

    #29000
    GlifTekGlifTek
    Licensee

    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!

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