Tasks With Argumetns

I am having some trouble with adding a task with arguments. I tried something like the following but I get the error:

TypeError: someFunction takes exactly 5 arguments (4 given)


 taskMgr.add(self.someFunction, 'moveToLocTask', priority=0,extraArgs=[a,b,c],uponDeath=None, appendTask=False, owner=None)
            
    def someFunction(self, task,a,b,c):        

        return Task.done

Could someone give me an example of how this should look?

I tried something similar, and it also complained about the number of arguemnts, so I added one to extraArgs, just to see what was what.

        taskMgr.add(self.tester, "debug_tester", extraArgs=["why two","something stupid"])
    def tester(self, task, dumb):
        print repr(self)
        print repr(task)
        print repr(dumb)

It output:

So, I took a look at the Task stuff, basically here’s some code from “taskMgr.add” that should clear things up:

            if extraArgs == None:
            extraArgs = []
            appendTask = True

        # if told to, append the task object to the extra args list so the
        # method called will be able to access any properties on the task
        if appendTask:
            extraArgs.append(task)

        task.extraArgs = extraArgs

So here’s what happens: normally there are no extraArgs, so appendTask gets set true, which gives you your task item right away. If you have extra args though… it won’t give you the task item unless you explicitly request it.
[/code]

Try changing appendTask to True. But, I think you then need to make the “task” argument the last argument of your function.

Or, you could just omit the task parameter from your function, unless you really do need it. Many functions don’t.

David

actually, the task is still at the beginning. I’ve also updated the wiki to reflect this.

Thanks. Yes changing appendTask to True and putting task at the end worked great

What do you mean??? When there’re extra args, shouldn’t the task be the last one???
I tested it here, and I get the same results of Boxy, the “task” argument goes in the last argument of the function…

Anyway, thanks for the topic, help me a lot.

Sorry for my english btw…

that was a mistake on my part, I misread the code when I was documenting it.