How can change colours of the objects automatically?

Hello everybody, I’m still having problems with my game, I’m trying to make that with a python script my objects changes his colour automatically, I added this code to the camera with a sensor type “always”:


import bge
import random
import time

from bge import logic
from bge import constraints

objects = logic.getCurrentScene().objects

level= 4

object_1 = objects["blue"]
object_2 = objects["red"]
object_3 = objects["yellow"]
object_4 = objects["green"]

for i in range(level):
    switch(random.randint(1, 4)):
        case 1:
            object_1.color(0,0,1,1)
            time.sleep(2)
            object_1.color(0,0,0.75,1)
            break
        case 2:
            object_2.color(1,0,0,1)
            time.sleep(2)
            object_2.color(0.75,0,0,1)
            break
        case 3:
            object_3.color(1,1,0,1)
            time.sleep(2)
            object_3.color(0.75,0.75,0,1)
            break
        case 4:
            object_4.color(0,1,0,1)
            time.sleep(2)
            object_4.color(0,0.75,0,1)
            break

What I’m trying to do is:
1 generate few Random numbers between 1 and 4 and according to this number select 1 object, change his colour, wait a couple of seconds and finally return it to the original colour, at this moment my script don’t do anything :frowning:

I hope somebody can give me a tip.
Thank you very much.
Regards.