Setting an object to a random position in the BGE I'm programming a game, and I have an empty that I want to be dropping enemies randomly throughout the map.  I have the following logic bricks and Python script right now:

import bge


def main():

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

    sens = cont.sensors['mySensor']

    if sens.positive:
        own.worldPosition = [own['xPos'], own['yPos'], 30]

main()




My empty is staying in the same place, but it is at least adding enemies every second.  How can I make the empty go to the random positions that are being generated by random actuator (I would have used the random module but it wasn't working last time I tried it).
The problem is that your script controller is on the Enemy Dropper object and attempts to reference mySensor which does not exist on that object. If you check the console, accessed by Window > Toggle System Console (only on windows systems), you will see an error.


  Traceback (most recent call last):
    File "Setting Position.py", line 9, in 
  KeyError: 'value = gameOb[key]: KX_GameObject, key "mySensor" does not exist'
  Python script error - object 'Enemy Dropper', controller 'Python':


To make it operable, add the mySensor sensor to the Enemy Dropper object's logic bricks.