How do I make dropped items keep their own data (name and value) so the drop zone can read it reliably? I want each dropped item to retain its Data structure when created, without needing arrays or hardcoding every item.
The expected result
When I drop a draggable item onto the drop zone:
A new dropped item is created
The dropped item has the same Data.name and Data.value as the DraggableItems
Each DroppedItem’s Data structure (name and value) is read and used by the DropZone
The drop zone can read each dropped item’s data correctly
(Ultimately I’d like to create a dynamic drag and drop game, where items values are attached to item names)
The actual result
Copying the Data structure from draggable → dropped does not work
Events
Conditions
Actions
DraggableItem → Was just dropped
Create DroppedItem at (DropZone.X(), DropZone.Y()) on Base layer
DraggableItem → Is in collision with DropZone
Pick nearest DroppedItem to (DropZone.X(), DropZone.Y())
If you’re using the Variable() expression then you don’t need to use it anymore. I think the issue could be that you used Variable() for Name which I’m assuming is a string and since it’s expecting a number it’s returning 0. The old expression for strings is VariableString(). Neither expression is needed anymore.
I’m not good with arrays my first instinct is to always use a structure. And I’ll remove the pick object actions I added it to try to force my logic to work, I’ll try using an array.
Hold on, please ignore that, I don’t know what I was thinking. You are already using a structure and should keep it that way. For some reason I read it as if you were trying to associate “name” with a value but that’s obviously not the case so just ignore me
A different way to go about it would be to avoid structures and arrays altogether, and just give those variables to the objects directly. So it would end up being “Item.name = draggable.name” instead. There was an update some time ago that allows you to edit variables of an entire object group, which is very convenient for this sort of thing. But either method works.