How do I make DroppedItems retain their own data so it can be reliably used by the DropZone?

How do I…

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())
Trigger once DroppedItem.Variable(Data.name) = DraggableItem.Variable(Data.name)
DroppedItem.Variable(Data.value) = DraggableItem.Variable(Data.value)
Change animation of DroppedItem → DraggableItem.Animation::Name()
Delete DraggableItem

1 - i think you should remove pick nearest item

2 - i am not sure i am reading it correctly so just to make sure
Change variable of DROPPEDitme set to variable of DRAGGABLEitem

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.

If I’m reading this correctly, it would be

DroppedItem.Data.name = DraggableItem.Data.name

The extra conditions are not necessary. When using the “Create an object” action, the new object is automatically picked for the remaining actions:

draggable was dropped   |    create Item
                        |    Item.Data.name = draggable.Data.name
                        |    Item.Data.value = draggable.Data.value

Also, why not use a structure instead of an array? Then you could have “name” be the index leading to Value, rather than two separate elements

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 :laughing:

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.