I’m trying to make my first game, a pixel RPG, and everything is going well except for a little problem that is keeping me stuck: I would like the player to have the ability to drop items from their inventory on the ground, in every room, and make them visible on the map and interactable; also I would like them not to disappear after leaving the room.
I’m sorry if my English is bad but I’m not a native speaker, I hope anyway that will be understandable.
In the meantime, thanks to those who will answer!
I assume, you have a system in place already to pick up items?
If you drop an item (depends on your system/drag out of inventory/click drop in menu)
You crate the item that can be picked up on the player position and save the items needed data (location/name/etc) into a global variable structure.
When you start a scene, create all relevant items from the global structure.
First of all thank you for the quick answer!
Yes, I had already thought about creating the items with a system like that, in fact I had already created the structure with the coordinates and the scene where every item is located, but I don’t know what kind of event I should use for creating them at the beginning of the scene. I tried to create a “For each child” event, but I didn’t understand well how it works.
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)
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.
Thanks for your detailed answer, I’ll try it right away.
I applied the system you suggested, obviously making changes to adapt it to my project, and it seems to work perfectly! Thanks a million for your time! While I’m at it I’d want to ask another question: how can I not drop the item in a solid object, for example a wall?
well the first placement of your items should be choosen by hand, and since the drop should happen at player position, it should also never be on impassible terrain, since the player cant go there?
Sorry, I didn’t specify that the droppable items are solid so I can’t drop them at player position. I’d like they fall behind the player but it would a problem if behind him there was a wall.
you could just try to use the separate objects action. could be janky, could work fine, idk, might be worth a try.
otherwise a while loop could work, before storing the data of the object, that checks if in collusion with impassible terrain group.
like create object at players back
set var angle to 0
item is in collusion with impassible
place item around player with distance = itemsize and angle= variable angle
add+90 to variable angle
if variable=360 do what you do when player cant place item, ether back into the inventory, or delete it.
Thanks, I’ll try and I will let you know.