- This topic has 5 replies, 5 voices, and was last updated 2 years, 3 months ago by kdv.
-
AuthorPosts
-
2020-04-23 at 11:54 pm #26489sleamanParticipant
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!
2020-04-24 at 8:21 am #26503Ivan LyubovnikovStaffI’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:
Attachments:
You must be logged in to view attached files.Co-founder and lead developer at Soft8Soft.
2020-05-07 at 10:10 pm #27387sleamanParticipantFantastic, thank you very much for explaining
2020-06-19 at 12:47 pm #29000GLiFTeKCustomerThere’s a standard workaround to deal with this situation. You should extract “when dragged over” puzzle into a separate procedure as follows:
oh man this just got me out of a rut with this issue.
thanks!
Visit the GLIFTEK Verge3D Plugins Store!
GLIFTEK.com for Plugin Documentation & LIVE DEMOS!
LIKE The GLIFTEK Facebook Page for updates!
Join the Verge 3D Discord Server!
plz share Discord link & on your signature!2021-10-13 at 4:00 am #46106CrunchCustomerblessings be upon you Ivan! that technique was really helpful. Thank u!
2022-09-01 at 11:49 am #55454kdvParticipanton 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 coding. 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 the meaning at all.
-
AuthorPosts
- You must be logged in to reply to this topic.