SpawnBug (Blend)

Press space. It will spawn object.
Sometimes it will spawn two objects at same time, i only want to spawn one at a time.
Can somebody take a look and fix it please :slight_smile:
Thank you.
http://pasteall.org/blend/index.php?id=44888

It spawns always two objects because the script is triggered two times, you can check it with the print() function.
First it will triggered when the sensor is positive and a second time when the sensor is negative again but sometimes you can’t see it because it spawns the same objects (random).

To fix the problem you simply need to check if the the sensor is positive:


import random
import bge

cont = bge.logic.getCurrentController()
own = cont.owner

sensor = cont.sensors[0]
#or
#sensor = cont.sensors['sensor name']
    
    if sensor.positive:
        own['item'] = random.randint(1, 2)

Thank you. Amazing job :slight_smile: