Need help with lists in a python module

I’m working on enemy attacks in a RPG simulation. My idea is to have the enemy do an attack animation when it’s close enough to the player, and when the frames of that animation is between 35-50 I want to execute the attack function: checking for collisions with the hitbox, look for “player” or “destructible”, and do damage to those, only within the “critical frames” of the attack animation (35-50)

My idea for sorting through the hitObjects and making sure it only attacks ONCE per target is for the enemy to make a list of the hitObjects during the critical phase. If the object is not in the list and is a player or destructible, do damage, then add it to the list. I then clear the list when the critical phase is over.


from bge import logic

hitList = []

def Attack(args, param, etc, hitList):
    
    if enemy.getActionFrame > 35 and enemy.getActionFrame < 50:
        if hitboxCollision.positive:
            Do all the damage stuff stuff()
            hitList.append(hitboxCollision.hitobject)
    else:
        hitList.clear()

def main():

    if own.getDistanceTo(player) <= 4:
        Attack(args, params, etc, hitList)

(I’m on my phone so sorry I can’t write proper code, but this pretty much the stuff in some pseudo way)

This works when I have only 1 enemy in the scene.

My problem arises when I add more enemies. I think the different instances of enemies (which I spawn through scene.addObject(enemy, pos)), share the same list, because the second enemy doesn’t even have to hit for the first one to do massive damage… When I check each enemy’s list through debug it is as if both enemies handle the same list, not making their own. If I define the list in the main function then it gets cleared every frame that main is called. I’m running the script as a module because that is the only way I could get the list to be “global” and not reset each run through main… Baaah I’m sry I’m so bad at explaining in a simple manner xD hope you understand, I can send a blend later, and I’d be glad to speak with anybody willing to help in private.

Looking forward to your help, thanks <3

I found the answer just after I posted… I did: if not ‘hotList’ in own: own[‘hitList’] = [] in the main function…I guess it works as an initializer.

Sry. Mark it as solved or just delete the post? Up to the gurus