Hi. I’m making a game where there is a main scene, and several other scenes that are like rooms, and you would often leave in and out of them to the main scene. Each scene has collectibles, and I would like to make it so that re-entering a scene does not cause these collectibles to respawn, as right now, after picking up the collectible and leaving the scene, if you go back into the scene at a later time, the collectibles are still there and you can pick them up again.
You could make the spawn location objects have a condition that if you have those collectibles in your inventory to not respawn them.
One way is to store an id for the object in a global structure as it’s collected and remove it if the collectable object id is in the global structure when you start the scene.
To achieve this:
- give the collectable objects a unique numeric id (say called “
Id
”) in the scene editor so that no 2 collectables in a scene have the same id. - create a global structure, say named “
CollectedObjects
” - When you collect a collectable object (in this example called “
CollectableApple
”), setCollectableObjects[CurrentSceneName() + CollectableApple.Id] = 1
- Add an event so that at the beginning of the scene that goes over each collectable object and deletes if from the scene if
[CurrentSceneName() + CollectableApple.Id
exists as a child ofCollectableObjects
.
.
Hi, sorry. I’m quite new to GDevelop, and I can’t figure out how to give an object a unique numeric id.
Hi. There is no inventory. Just collectibles by using a score or specific number of that collectible required to unlock something. Additionally, the collectibles are many instances of the same object, so I’m not sure this would work unless I am understand incorrectly.
sorry my second previous message was not a reply to you, so I am replying now so you may hopefully see it.
In the scene editor, click the 3 dots beside the object in the right hand panel to get this popup:
Thank you Would you min showing me what the line of code would look like in GDevelop that you mentioned earlier? I don’t quite understand what exactly it would like like as the conditions and actions in the events.