Passing a parameter to a task

I am working on a tank game with a world, a tank object, and a boss object. The world is created, then the boss, then the tank. The tank is passed a pointer to the boss object to allow for tank-boss communication without world intervention (for collision events and other things).

When the tank passes through a certain volumetric trigger, it tells the boss to activate. I want the boss to continually face the tank using the lookAt command. The problem is that the boss doesn’t know about the tank, and I can’t pass the boss a pointer to the tank because the boss is created first, and there’s a circular dependency there.

Since the tank knows about the boss, and since I already have a task on the tank handling movement, I wanted to the tank to pass the boss it’s own position in a task, updating boss.tankPos every frame. The problem I am having is passing the bossPointer to the task.

I currently enable the tank movement task in the following way:

        # add a task to handle tank movement
        taskMgr.add(self.handleMovement, "handleMovement")

I tried adding bossPointer in there, both as an argument, and as a list, and it didn’t like it. How can I edit my handleMovement task initialization so that the bossPointer gets passed to the task?

I want to do this without making the bossPointer an actual attribute of the tank class, because that would create a local copy of the boss, which isn’t what I want.

Any ideas?

To answer your question, look at this post:

https://discourse.panda3d.org/viewtopic.php?t=3

put the list of arguments after the name. The task parameter is no longer needed, but the self parameter is (thats discussed in the post). You should also make sure to include the keyword extraArgs=[list of arguments] when you add your argument list.

I do wonder about the statement you made about the bossPointer as an attribute of the tank class and the local copy. I thought that python just uses references for objects, where python will keep the object until all refrences to that object are destroyed. Could anyone clarify this for me?

I was thinking something like this in the tank class:

def setBoss(self, bossPointer):
    self.boss = bossPointer