I Need Help Making an Item Re-spawn at a Random Time

Game Link:
https://flowlab.io/game/view/1464621
Hello! I need some help on making the pizza re-spawn in the same place, but in a random time between 4-8 seconds after it is collected by the pineapple (please look at the pizza’s behaviors). This is my first game and I would really appreciate it if someone could help. Thank You!

This request is kinda hard to explain in text, and if it’s your first game my explanation may be a little confusing, but I’ll try to help anyway. There are a few things that should to be altered in order to achieve this affect.

Primarily, you’ll need to have the pizza spawn code be allocated to another object. Because the pizza is being destroyed once you touch it, no further code can be run on the pizza object because it has been deleted from the level. This means the timer connected to the destroy code will not activate.

Second has to do with the spawn code itself. Once you have moved the code to another object to cause the pizza to spawn, you must choose a location based on pixels in the grid. For example, the pizza on the left is located at (3,5). In the spawn code, however, the location is based on pixels not the grid. Since each grid square is 32 x 32 pixels this means you need to put 96 for the x and 160 for the y. Do not connect anything to the x or y inputs in the spawn code unless you wish to change the x and y positions.

Finally, to have the pizza be spawned in a random amount of time you must connect a random code block to the delay input of the timer. Because the timer is based on 1/10 a second you must set the minimum for the random block to 40 and the maximum to 80.

I will follow this up with image examples.

Annotation 2020-07-29 225206

Here I am sending a message to the player character to spawn the left pizza after it is destroyed.

Annotation 2020-07-29 225857

Here the player character is receiving the message from the pizza. This causes the random code to generate a number between 40 and 80. This random number is saved as the delay in the timer and causes the timer to start. Once the timer goes off the pizza is spawned on the pixel point of (96, 160).

Unfortunately the way this is done, you will need to create a separate pizza object for the pizza on the right or else it will just spawn on the left again. Just create a new pizza for the right and duplicate the steps above, but for the new object.

This is probably the simplest way of doing it without involving too much checks and extractors to save on object spaces.

Thank you so much BitWit for explaining to me how to make the pizza re-spawn! The game now works just as I wanted it to! : )

No, problem! Glad I could help :slight_smile: