How to add single time collectible

Hi, how can i add collectibles to my levels and save collected ones information and delete them in next run (i can figure out for 1 item but for 60 or more items do i have to code all of them one by one)

Hi!
Alternatively, you can create objects and add them to the same group. To check the collection, check not with the object, but with the corresponding group.

1 Like

Thanks for answer, i know groups i was trying to figure out single time collectible for levels like 10 stars in level 1 and if you collect them total number will be stored on global variable and will not appear in next game

Hello, first thing that i have in mind : That star is picked, set a variable to 1 and save it, when a new game starts and that variable is 1, hide/delete star.

Do you mean you close the game and start it again? Or just a replay while the game is running?

If the former (close game and open it up again later) then keep in mind that global variables only have values in them while the game runs. Once you close the game and start it up again, the global variables will be reset. The solution is to use storage

Steps to achieve what you want:

  1. Give each star a unique id in the editor.
  2. When you collect a star, store its id as the key in a global structure and with 1 as a value.
  3. When level is complete, save that global structure to storage.
  4. Add an event at the start of the game to read in the saved data from storage into the global structure.
  5. Finally add an event at start of the level that checks whether each star’s id is a child in the global structure and deleted the star if so.

Note, if you only want to keep track of the collected stars while the game is running, ignore steps 3 & 4

2 Likes

i was meaning closing the game and starting again, is there any video or example about steps you mentioned. i watched save load video of gdevelop but its a bit different problem.

How is it different? You load the data at the start of the game and save it at the completion of each level.

And have you checked out this video on loading and saving to storage?

no, i didnt. Thanks i will watch it. i mean i learned basic save load system but i didnt completely understand steps you write (1. step is giving object variable and changing by hand from editor if i understand right)(2.and 3. step Saving & Loading (Storage) - Advanced Tutorial - GDevelop - YouTube something similar to this video)(4.5. reading and checking for each object id and it its 1 delete it)


i found this solution in forum. Do you think is it has any downside (when i add new coin sprite it resets storared ones but if its not important for final game its okay)