How to Transfer a task from an Object to Another?

Hello All,

Here come again an annoying question from me…

Here is my issue. I want to implement an advanced bonus pickup system.
Basically , Entities picking up an object would give player special abilities or special timed effects .
Actually all my special ability are created as task which affect the player properties.

What i would like is to have the task defined and created by the “BONUS” object but the task played and managed by the player object.

The aim is to have easiest flexibility to add new Abilites/effect. this way it’s just adding either new “Bonus” either new Abilities in existing "Bonus " and not adding code to existing Entity.
In short, it would be : How can Object A create a task and give it to Object B for Object B to run the task and apply it to itself?

One workaround i found is to have an object C as “Effect Repository” but this would be a huge object to code!

Hmm, I don’t quite follow your question. A “task” in Panda is really just a method that is run once per frame. The task may be created by any object, and the method does not have to be part of the creating object.

So you can do someting like this:

class ObjectA:
  def handleObjectB(self, objectB):
    taskMgr.add(objectB.handleTask, 'handleTask')

I’m afraid I don’t understand what you mean by “Effect Repository” at all.


In fact my issue is that from your example, handletask is a method of objectB so it’s written and maintained in ObjectB code.

Also , from what i understood of task system, Object X has no way to know which tasks (from him or from other objects ) are affecting him?

Please forgive me, but I still don’t understand the problem. You could just as easily make handletask a method of objectA if you prefer it that way; in that case, you may need to pass objectB as a parameter to the method using the extraArgs option.

This is correct–there’s nothing built into the task system to look up the tasks that are affecting a particular object. If you require this list, it will be up to you to maintain it.