How to make item only collectable once?

Hey there, I’ve just been returning to my game after a couple years of not working on it much and I’m having trouble figuring this one out. At one point in my game, the player has to collect 5 of the same item in no particular order. These items appear once you’ve collected a different item, and right now, they’re tied to the “swap” function in each room’s script upon entering. E.g.:

on enter do
if item1==1 then
swap "item2" at 22,11
end
end

The problem I’m having is that since it’s tied to entering, the item respawns when you re-enter the room. How would I go about making these items collectable only once in each room while still using the same item tile in each of the 5 instances where it has to be collected? Thanks all!

Hi,I also need to return to my pulp game I started a long time ago... :sweat_smile:
English is not my native language, so correct me if I’m wrong in understanding your problem.

But my solutions are this:

**Solution 1**

If the item is not animated, I would use the frame number of the item to represent the state that the item is in.
So I would not use swap at all, but set the animation fps to 0 of the tile, and each frame is a different state the tile is in.
This way you can just tell the location of the tile to switch to a different frame.

	// Change the tile state
	tell tilex,tiley to
		frame 1
	end

By controling the frame on a certain location in the room, it’s not a problem if the item gets respawned when the room resets upon re-entering.
You should probabaly put this in an event handler, where you have can re-use the logic in other rooms if needed.

Here is an example of my own code, where I read the frame of the tile on a certain location and switch it to a different frame, to the state that it should be.

// Get the frame of the tile on a certain location
frameNumber = frame tilex,tiley
if frameNumber==0 then
	tell tilex,tiley to
		frame 1
	end
else
	// Change the tile state
	tell tilex,tiley to
		frame 0
	end
end

Even if this is not the answer for your problem, I think that the state control with frames is a useful pulp concept.

**Solution 2**
I think the problem that you describe happens because the tile was set at that location in the room in the visual editor.
So another solution would be to hard-code the creation of the item tile upon entering the room by default, and not from where you visually set up the room.
This way the item can be animated and be simply swapped with another upon entering the room.

Let me know if you need more help with this.