How to create an efficient drop system?

you need a counter and an object group items or pickupitems

set variable(counter) to 1
repeat GlobalVariableChildCount(items) times
among objects items (group) create object named GlobalVariableString(items[VariableString(counter)].name)
at position
GlobalVariable(items[VariableString(counter)].x) / GlobalVariable(items[VariableString(counter)].y)
add+1 to variable(counter)

this way it goes thru each of the children of globalvariable items and creates item.1.name, item.2.name etc from the structure items

when you drop the item, you write its data into the structure.
your drop events and as a subevent of that:
set GlobalVariable(items[ToString(GlobalVariableChildCount(items)+1)].name) to itemgroupname.VariableString(name)
set GlobalVariable(items[ToString(GlobalVariableChildCount(items))].x) to player.x()
set GlobalVariable(items[ToString(GlobalVariableChildCount(items))].y) to player.y()

the more tricky part is, to have it sorted.
one way would be that you use a deeper structure. you also need to save the info in which scene it has to be placed.
the best way would be a structure that is presorted by scenes.
like globalstructure items.scene(num).count.name
then you load only the items, corresponding to the current scene.

if you pick up an item in that scene (you dont know the count number), but you can clear the structure item.scene and rewrite it completly with the object variables of the items, present in the current scene.
like if item is picked up
clear structure items.yourcurrentscenenum
and then a repeat for each items loop
set counter to 1
write data of items into scructure
counter add 1

this way your list is always sorted.

1 Like