I'm under the assumption you're still using save states to load and save the game? If you are I suggest you learn how to use .ini file as soon as you can. They're a little bit intimidating, but it's very rewarding once you get to know them. I suggest you follow this tutorial to learn it:
So as an example, I'd typically store collectible data as follows.
global.collectible1 = 0;
global.collectible2 = 0;
0 being false (In other words I didn't get it yet), and 1 being true. You'd typically call the following code when you start up the game, or click play:
ini_open("save.ini");
global.collectible1 = ini_read_real("COLLECTIBLES", "collectible1", 0);
What ini_open does, is it looks for a save file stored in your localappdata folder called save.ini, and if the file exists it loads it into your memory, otherwise it creates the file. the next line creates a global variable (global means it can be accessed from any object, not just the one it's initialized on), and reads data from the file. ini_read_real means it reads a real number, ini_read_string reads a string from the file. The first parameter is basically a section in the file, in our case we call it COLLECTIBLES. It's good practice to capitalize the sections to distinguish them easier. the next parameter reads "collectible1", that's the name of the value in the COLLECTIBLES section. The 3rd parameter is a default value, so in case the player hasn't played before or collectible1 doesn't exist in the file yet, it default global.collectible1's value to 0.
In your collectible object, you want to add something along the following lines in your create event:
if (global.collectible1 == 1) //In other words if it has been collected
{
instance_destroy(); //Destroy itself
}
Remember that you need to load up from the ini file at the start of the game, otherwise you'll run into errors since the variable doesn't exist.
Okay, so now onto collecting the collectible. In the Collides with player event on the collectible object, add the following lines of code:
global.collectible1 = 1; //We're now setting the value to one so that the game knows we collected it.
//Let's make sure to tell the save file too!
ini_write_real("COLLECTIBLES", "collectible1", global.collectible1);
//And last but not least, we now need to remove the collectible from the playfield.
instance_destroy();
ini_write_real has a very similar structure to ini_read_real. First parameter is "COLLECTIBLES", which once again is the section, "collectible1" is the name of the value, technically called the Key, and the third parameter is the value we want to put into the file. In our case we're putting global.collectible1's value in which equates to 1 since it's now collected.
With all that done, when the player dies simply restart the room. Your collectible will now no longer appear a second time. Keep in mind that using save states alongside ini files will cause a lot of issues, so rather move to ini files completely. After all, they're much more reliable. If you need any help, feel free to drop me an email at "
[email protected]". I'd be more than happy to help you in my free time.