Choose random or specific object, delete it, and replace it

This must be simple, but I cannot figure out how to code it, so please forgive me since I am new to game creation. :slight_smile:

  1. How do I choose a random object, delete it, and replace it with another object?
  2. How do I choose a specific object, delete it, and replace it with another object?

For example, there are many blueBox objects in the scene. I want to delete just one of them, and replace it with a greenBox object.
Thank you!

First is easy, just do following (adding additional conditions if necessary):

It’ll replace object spring with an object grid.

For the second, you’ll need some instance tracking (GD doesn’t have one built-in ATM), like variable id that has unique value for every object.

Delete A and replace with B

There is an action to select a random object A, but before delete it, you should create B or save A’s position: Other way, if you delete A first, then you will not know where to create B :wink:
1 - Select random A ===> Create B at A’s position ===> Delete A or
2 - Select random A ===> Save A’s position in two variables ===> Delete A ===> Create B at variable position
Of course (1) is preferred, since you haven’t to create a variable.

It’s almost the same, but instead selecting a random A (this is an action), you need a condition. I can’t help here, since the condition is given by your game. For example if the A you want to replace is the clicked one, the condition is “Button pressed”+“Cursor is over A”, then create B at A’s position, and finally delete A :slight_smile:

EDIT: I didn’t note that Darkhog had already answered… is the same explanation, but shorter :smiley:

Thank you Darkhog and Lizard-13. This helped me a lot, and I was able to get my game working how I wanted. :slight_smile: