Picking Items with data

I know how to use Pointers etc, already. My problem is, i m coding a small RPG for my friends and me, and ofc it needs collectable items. the collecting or the items themself are no problem, my problem is: till now i can only attach objects to rootnode which can be collected (eg: i collect object “corn” and one corn is added to inventory), but i want a graphical object on the ground, which has a specific number of items, or a damage value, etc, to drop and recollect already used weapons & tools. current status d be that i can damage a tool, but if i drop and recollect its completly new.

i wasnt able to find any links, which explain a solution.
can someone explain (or link, if theres a tutorial) how to collect “objects”/items with specific item data?

tyvm

Do not create a new object when you drop or collect on object. It has to be the same java instance.

You can setUserData() on your spatials.

…but if you treat Spatials as your game objects then you are going to have a bad time and struggle every day. Unfortunately, the next level up where you keep them separate is harder for beginners to understand.

i had the thought some minutes ago: wont it be possible to make a new class, extend Spatial and add methods like setCount(int i) and getCount()?
cant test it atm

You shouldn’t extend Spatial.
You could create a “Custom Control” (by extending AbstractControl), see the Wiki for that.

You’d have a “ItemControl” and can implement set/get Count on that level

And also: It’s better to have a seperate structure for those items, since it’s pretty valid that a dropped item might be removed from the SceneGraph

I suggest the following approach:

Give each userdata some kind of id. This can be as simple as a unique integer you increment each time.

Now you can easily create a HashMap<Id,AnykindOfData> in your game code, where you store anything.
Also this allows most of the logic to work, even if you do not have a spatial attached. (like damage is kept if it is in inventory)

i ll try it. thx for the help