removeTask without triggering uponDeath

I maybe found the problem behind some problems reported in my questions thread.

If I remove tasks from the task manager they usually trigger an uponDeath function and that works fine. Now I got situations where I want to remove tasks from the manager without triggering the uponDeath function. Reading Task.py line 416+ I wonder if that’s possible?

setUponDeath(lambda:0) ?

Huh? I don’t see how to apply that? There’s no TaskMgr.getTask(“name”).setUponDeath(bla)?

Or do you mean when I originally add the task? No, I need a real uponDeath there.

What do you mean? Sure there is: http://www.panda3d.org/reference/python/classpanda3d_1_1core_1_1PythonTask.php#a7c33bb2cf46038674a5fe34de658c182

Edit: or maybe it’s the taskMgr.getTask(‘foo’) you’re missing. There’s no such method, because there might be multiple tasks with the same name; instead, there’s taskMgr.getTasksNamed(‘foo’), which returns a list. If you’re confident there’s only one task named ‘foo’, you can just get the first element of that list.

Or, you can save the Task object that is returned when you create the task in the first place.

David

It’s safer to set it to None, since each task may expect different set of arguments.

@ ynjh_jo didn’t catch the context of what you said.

Yeah I did:

for thistask in taskMgr.getTasksNamed(task):
				thistask.setUponDeath(lambda:0)

where task is the name of the task(s) that I used for AI stuff. I still try to understand what the problem is when i get back to the menu or land on a planet - all ships get deleted and then some task comes back, wants to do an operation on the nodes, but those are already removed. But I first remove the tasks, then the nodes, so there should be no problem.

What does that mean? Something like:

mytask = taskMgr.add(bla)
mytasklist.append(mytask)

? And then remove those?

EDIT:
In a related issue … When I create intervals I append them to a list, like

myint = Interval(bla)
myintlist.append(myint)

When I print that after some operations I often get something like:

[None, Sequence-20 dur 4.5]

Does None mean that the interval has ended? Or been quitted? Or deleted (del)?

ynjh_jo meant to pass setUponDeath(None) instead of setUponDeath(lambda: 0).

Well, what can I say to this? This sounds like a logic error somewhere in your code. Perhaps you have not deleted the appropriate task; or perhaps your task has a pointer to the wrong node. Also note that when a task removes itself (e.g. in a nested call), it doesn’t interrupt its current frame–it continues to run until it returns task.whatever.

Yes, that’s what it means.

No, none of those can change an existing interval to None. Nothing can, sort of reassigning into the list. So this means one of three things:

(1) You are reassigning None into the list, with e.g. myintlist[0] = None

(2) Your added None into the list in the first place without realizing it. Not possible with the code snippet you posted, but maybe some of your code looks different than that.

(3) The interval is not in fact None, but is just something that says “None” when you print it. I don’t know of any intervals that do this, though.

David

Eureka, I got it:

jumpin_duration = 1.25
jumpin_scalein_int = LerpScaleInterval(self.ShipModel, jumpin_duration, Vec3(self.ModelScale), Vec3(self.ModelScale)*0.01, blendType="easeOut") # easeOut
jumpin_posin_int = LerpPosInterval(self.ShipModel, jumpin_duration, Vec3(x2,y2,0), Vec3(x1,y1,0), blendType="easeOut") # easeOut
# do we need the reparent to render?
jumpin_parl = Parallel(jumpin_scalein_int, jumpin_posin_int, Func(self.reparentToRender, self.ShipModel)) # name="jumpin_parl"		
jumpin_seq = Sequence(jumpin_parl, Func(self.setInitVel)).start()
print "jumpin_seq", jumpin_seq

prints:
jumpin_seq None

jumpin_duration = 1.25
jumpin_scalein_int = LerpScaleInterval(self.ShipModel, jumpin_duration, Vec3(self.ModelScale), Vec3(self.ModelScale)*0.01, blendType="easeOut") # easeOut
jumpin_posin_int = LerpPosInterval(self.ShipModel, jumpin_duration, Vec3(x2,y2,0), Vec3(x1,y1,0), blendType="easeOut") # easeOut
# do we need the reparent to render?
jumpin_parl = Parallel(jumpin_scalein_int, jumpin_posin_int, Func(self.reparentToRender, self.ShipModel)) # name="jumpin_parl"		
jumpin_seq = Sequence(jumpin_parl, Func(self.setInitVel))
jumpin_seq.start()
print "jumpin_seq", jumpin_seq

prints jumpin_seq Sequence-8:
0.000 Sequence-8 {
0.000 Parallel-7 {
0.000 LerpScaleInterval-59: scale from 0.00325 0.00325 0.00325 to 0.325 0.325 0.325 dur 1.25
0.000 LerpPosInterval-60: pos from -83.1384 48 0 to -20.7846 12 0 dur 1.25
0.000 *Func-reparentToRender-14
1.250 }
1.250 *Func-setInitVel-15
1.250 }

Only difference in the code being the start() thing at the end!