Tasks Randomely Stopped Working

I’ve been using a jump task to allow my character to jump. Recently, Without changing anything to do with tasks, I now get an error. First I will show what i’m using, then I will show my error.

from direct.task import Task

class World(DirectObject):
    def __init__(self):

        self.accept("space", self.spacePressed)

        self.jumpReady = True

    def spacePressed(self):
        if self.jumpReady is True:
            self.jumpingTask = taskMgr.add(self.jumpingAction, "jumpingAction")
            
    def jumpingAction(self, task):
        #DoStuffNotIncluded

When I try to jump, I now get this error:

DirectStart: Starting the game.
Known pipe types:
  wglGraphicsPipe
(all display modules loaded.)
Traceback (most recent call last):
  File "C:\Users\Britany\Desktop\Panda3D\Panda3D-1.7.2\direct\showbase\EventManager.py", line 61, in eventLoopTask
    self.doEvents()
  File "C:\Users\Britany\Desktop\Panda3D\Panda3D-1.7.2\direct\showbase\EventManager.py", line 55, in doEvents
    processFunc(self.eventQueue.dequeueEvent())
  File "C:\Users\Britany\Desktop\Panda3D\Panda3D-1.7.2\direct\showbase\EventManager.py", line 122, in processEvent
    messenger.send(eventName, paramList)
  File "C:\Users\Britany\Desktop\Panda3D\Panda3D-1.7.2\direct\showbase\Messenger.py", line 388, in send
    self.__dispatch(acceptorDict, event, sentArgs, foundWatch)
  File "C:\Users\Britany\Desktop\Panda3D\Panda3D-1.7.2\direct\showbase\Messenger.py", line 473, in __dispatch
    method (*(extraArgs + sentArgs))
  File "C:\Users\Britany\Desktop\Panda3D\Panda3D-1.7.2\direct\gui\DirectButton.py", line 103, in commandFunc
    apply(self['command'], self['extraArgs'])
TypeError: jumpingAction() takes exactly 2 arguments (1 given)
:task(error): Exception occurred in PythonTask eventManager
Traceback (most recent call last):
  File "maincourse3.py", line 303, in <module>
    run()
  File "C:\Users\Britany\Desktop\Panda3D\Panda3D-1.7.2\direct\showbase\ShowBase.py", line 2630, in run
    self.taskMgr.run()
  File "C:\Users\Britany\Desktop\Panda3D\Panda3D-1.7.2\direct\task\Task.py", line 502, in run
    self.step()
  File "C:\Users\Britany\Desktop\Panda3D\Panda3D-1.7.2\direct\task\Task.py", line 460, in step
    self.mgr.poll()
  File "C:\Users\Britany\Desktop\Panda3D\Panda3D-1.7.2\direct\showbase\EventManager.py", line 61, in eventLoopTask
    self.doEvents()
  File "C:\Users\Britany\Desktop\Panda3D\Panda3D-1.7.2\direct\showbase\EventManager.py", line 55, in doEvents
    processFunc(self.eventQueue.dequeueEvent())
  File "C:\Users\Britany\Desktop\Panda3D\Panda3D-1.7.2\direct\showbase\EventManager.py", line 122, in processEvent
    messenger.send(eventName, paramList)
  File "C:\Users\Britany\Desktop\Panda3D\Panda3D-1.7.2\direct\showbase\Messenger.py", line 388, in send
    self.__dispatch(acceptorDict, event, sentArgs, foundWatch)
  File "C:\Users\Britany\Desktop\Panda3D\Panda3D-1.7.2\direct\showbase\Messenger.py", line 473, in __dispatch
    method (*(extraArgs + sentArgs))
  File "C:\Users\Britany\Desktop\Panda3D\Panda3D-1.7.2\direct\gui\DirectButton.py", line 103, in commandFunc
    apply(self['command'], self['extraArgs'])
TypeError: jumpingAction() takes exactly 2 arguments (1 given)

**** End of process output ****

If i’m not mistaken,
It’s now because i’m using “self, task” which isn’t allowing me to have a second argument.

But this wasn’t a problem before. Any ideas on how to fix this? I don’t believe I changed anything around.

Whatever is causing the error is not shown in the small bit of code you posted.
From the error I’d say you are trying to call the jumpingAction function directly, like self.jumpingAction() which will not work since it is set up as a task, and requires a task as second argument.
Also something about DirectButton in there, maybe you are trying to call the task function as a result of clicking a DirectGUI object, whereas you would actually want to call the spacePressed function.
Just some guesses since you are not showing the code.

Sorry about that,
I know i’m not showing the code.
Because the rest isn’t at all important.
I did, however, take out the button, So it’s all good.

In my posted code, You will see I called the spacePressed by self.accept, and jumpingAction by a task, Which probably means that’s not the problem. Again, I did not change the code, and it was working fine earlier today.

Maybe is

from direct.task import Task

The only thing that needs imported to run tasks? Other than that, I went through my script, and I don’t see anything wrong.

(From your error message)

Based on the above-quoted line, you appear to be attempting to call the method from a DirectButton somewhere - could we see that, please?

Removed it. I now get no error pressing space, but it still doesn’t work. (Not a problem with my jump task)

Is there a particular reason why you are not posting your code? Basically it is frustrating to try and help you when you ask how to fix a piece of code that you do not show us.

Look at it from our perspective:
“I spelled a word wrong, how do I fix it?”
“Can you show us how you spelled it?”
“OK, but I’ll only show you the first letter, the rest don’t matter.”

Obviously that’s an overstatement concidering not only do I see how that can be misleading, but it can also be taken as an insult.

However, I do see where you’re coming from.
So here you go:

    def jumpingAction(self, task):
        if self.isRising is False and self.taskCount is 0:
            self.isRising = True
            self.jumpReady = False
            self.taskCount+=1
            return task.cont
        if self.isRising is True and self.taskCount >=1 and self.taskCount < self.height:
            self.blaze.setZ(self.blaze.getZ()+self.height/self.duration*globalClock.getDt())
            self.isRising = True
            self.jumpReady = False
            self.taskCount+=1
            if self.taskCount > 0 and self.taskCount < self.height:
                return task.again
            if self.taskCount is self.height:
                return task.cont
        if self.isRising is True and self.taskCount >=self.height and self.taskCount < self.height*2-2:
            self.blaze.setZ(self.blaze.getZ()-self.height/self.duration*globalClock.getDt())
            self.isRising = True
            self.jumpReady = False
            self.taskCount+=1
            if self.taskCount >= self.height and self.taskCount < self.height*2-2:
                return task.again
            if self.taskCount is self.height*2-2:
                return task.cont
        if self.isRising is True and self.taskCount >= self.height*2-2:
            self.isRising = False
            self.jumpReady = True
            self.taskCount = 0
            return task.done

EDIT: You also must know my character does not do anything when I press space.
Space is working fine in general, Just not my code.
It is triggered based upon if I am not rising, And the task count is 0. The task count IS 0, and on start-up, isRising is false.
Pretty much sums up it should be triggering properly.

EDIT(2): I did a little experimenting. I had placed in a setText before return task.cont in the first part of my task. I then pressed Space, and it worked. It changed my text. But then I place it before self.taskCount+=1 on the second part of my task, And it did not work.
This must mean that something isn’t triggering the next part of my task. Not sure if it’s from return task.cont or what?

No insult intended, I thought it was a rather accurate analogy to the situation.

Here is a working example based off of your code.

from panda3d.core import *
from direct.showbase.ShowBase import ShowBase



class Game(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)
        self.blaze = loader.loadModel('smiley')
        self.blaze.reparentTo(render)
        self.accept("space", self.spacePressed)
        self.height = 0.0
        self.jumpReady = True
        self.isRising = False
        self.jumpHeightCurrent = 0.0
        self.jumpHeightMax = 1.0
        self.jumpSpeed = 5.0

    def spacePressed(self):
        if self.jumpReady:
            self.jumpingTask = taskMgr.add(self.jumpingAction, "jumpingAction")
            self.jumpReady = False
            self.isRising = True

    def jumpingAction(self, task):
        done = False
        dt = globalClock.getDt()

        # are we rising or falling?
        if self.isRising:
            self.jumpHeightCurrent += self.jumpSpeed * dt
            # don't go higher than the maximum
            if self.jumpHeightCurrent > self.jumpHeightMax:
                self.jumpHeightCurrent = self.jumpHeightMax
                self.isRising = False
        else:
            self.jumpHeightCurrent -= self.jumpSpeed * dt
            # don't fall further than we started at
            if self.jumpHeightCurrent < 0:
                self.jumpHeightCurrent = 0
                done = True

        # update the model's position
        self.blaze.setZ(self.height + self.jumpHeightCurrent)

        # if we are done, allow jumping again and finish the task
        if done:
            self.jumpReady = True
            return task.done
        else:
            return task.cont



Game().run()

Not at all accurate. Sorry for your confusion:(

However, Your example does not work.
I tried, And I move up a small amount, and then back down. No moving upward, Just warp up, then warp back down.
It is something wrong with setting my position.
I did a little testing using setText, and it seems to change constantly like it’s supposed to. But when I replace it with setting my Z height to my current height plus a small amount, I only go up once, then after the time intended, fall back down.

I’ve no idea what’s wrong with your installation, but the code teedee posted works like a charm. When you press space, the smiley goes up a bit and then down. All taking about a half second (0.4 to be precise).

What do you see when you copy the code, paste it into a file and run it with python?

When I run the file with that code he posted, When I press Space, My character disappears (Most likely flies too high at a too fast of a speed), And my camera view moves upward a very small amount, Then about 0.5 seconds later, My camera view repositions, and my character reappears back down to where he was before.

No errors, Just disappear, reappear.