How to get a list of objects in active game layer with python?

Hi, I’m kind of a noob at python and I’ve come across a situation that I can’t find a solution for.

I’m trying to write a script that goes through the objects in my game and looks for a specific property so the script can decide which object to spawn. I don’t want more than 1 copy of each object in play at any given time, so the I want the script to find which object or objects currently exist on the visible game layer and spawn the first object that hasn’t been spawned. This is my current script, but since the objects being spawned are in the same scene (but on a hidden layer), I can’t tell which one(s) have been added to the visible layer. Instead of scene.objects in the for loop, is there something like scene.active_layer.objects that I can use? Thanks for you help, it’s greatly appreciated!

import bge
import GameLogic

def BallSpawn(cont):    
    
    own = cont.owner
    scene = GameLogic.getCurrentScene()
    
    Ball1 = cont.actuators["Ball1"]
    Ball2 = cont.actuators["Ball2"]
    Ball3 = cont.actuators["Ball3"]
    
        # if there isn't a ball currently in play
    if own['BallNumber'] < 1:           
        
        ball1 = 0
        ball2 = 0
        ball3 = 0
        
            # go through the objects in the scene and see if any balls are out
        for obj in scene.objects:
            
                # if object is ball, it will have a property called 'Ball'
            if 'Ball' in obj:                    
                
                    # store which ball it is in a variable
                if obj['Ball'] == 1:
                    ball1 = 1
                    
                elif obj['Ball'] == 2:
                    ball2 = 1
                    
                elif obj['Ball'] == 3:
                    ball3 = 1                   
        
            # set which ball to spawn
        if ball1 == 0:
            own['BallSeed'] = 1
            cont.activate(Ball1)
            own['BallNumber'] = own['BallNumber'] + 1
            print("BallSpawn: Spawning Ball1")
        
        elif ball2 == 0:
            own['BallSeed'] = 2
            cont.activate(Ball2)
            own['BallNumber'] = own['BallNumber'] + 1
            print("BallSpawn: Spawning Ball2")
            
        elif ball3 == 0:
            own['BallSeed'] = 3
            cont.activate(Ball3)
            own['BallNumber'] = own['BallNumber'] + 1
            print("BallSpawn: Spawning Ball3")

Nevermind, lol! It was a stupid mistake and was very obvious once I really thought about it. I had a property named ‘Ball’ on another object and it’s default value was 1, so that was causing the problem. I just changed the properties on the objects that it looks for to something else (‘BallObject’ in this case). It works like it should now.

Also, I’m pretty sure scene.objects will only return the objects in the active or visible game layer if it’s executed at runtime. If someone could give me a definitive answer on this though, that would be appreciated. Thanks for your time!