script only works on most recently duplicated object.

When duplicating objects that have logic bricks already set up, only the most recently duplicated object will actually function properly. here is a very simple example of what is happening. the cube on the right is a duplicate of the one on the left. if you press play, only the cube on the right will run the script properly by teleporting around and changing color ever second. if you delete the cube on the right, the one on the left will work just fine. if you duplicate either of the cubes, only the newly created cube will work.

what is going on here? is there any way to fix this?

Not the most efficient (I don’t work with modules too often) but this should work:


import bge
import GameLogic
import pprint
import time
import mathutils
import Rasterizer
import random

cont = bge.logic.getCurrentController()
scene = bge.logic.getCurrentScene()
g = GameLogic


def repeating_actions(cont):
    own = cont.owner
    own.color = [random.randint(1, 10)/10,random.randint(1, 10)/10,random.randint(1, 10)/10,True]
    
    own.worldPosition.x = own.worldPosition.x + (random.randint(-10, 10)/10)
    own.worldPosition.y = own.worldPosition.y + (random.randint(-10, 10)/10)
    own.worldPosition.z = own.worldPosition.z + (random.randint(-10, 10)/10)

Basically you were having two objects run the module and the one that ran last would overwrite the own variable for both objects (Since it is a module) since the own varibale was never rewritten it used the last value given to it (The second object) and just did that. (I suggest moving other variables needed into the repeating action such as cont)

A simple test was to put a print(“RUN”) in there and see that it was printing twice for every one color movement.

Thank you!

Generally avoid any module-level variables when using module mode.
For example, the amended code will fail when run in a different scene if you were to use the scene variable.

You actually do not need to look up the current scene or controller - module mode provides the controller, and the owner of the controller is a KX_GameObject instance, which has a scene attribute.