Delete the first object created

An object is created every 1 seconds and the first object created is deleted every 2 seconds. How can I do this without deleting all created objects?

1 Like

I guess this is for the snake thing you mentioned in your other post I was about to respond to. The way programmers usually do a snake game is using an array and pop-ing the first value, but as far as I know there are no array (I planned on creating an extension for that). What I would do here is setting a scene variable index to 0, and every time you add an object, you add 1 to the index, then set the object variable id of the newly created object to the value of Index. Then each time you want to delete the first created, tempvar = 99999 and make for each object if id is smaller than tempvar set tempvar to the instance variable id, and after that for each remove object with variable id = tempvar. Optionally, if you don’t want to create more than let’s say 95 instance of the object, you can make tempvar by default 96 instead of 99999 and between adding 1 to index and setting it to the id of the object an event with condition index is 96 and action set index to 1.

1 Like