-2

I have a panda program that simply calls other tasks like so:

from direct.showbase.ShowBase import ShowBase

from direct.gui.DirectGui import *

from GameObject import Player

class Game(ShowBase):
    def __init__(self,manager=None,size=None,apppath=None):
        ShowBase.__init__(self)
        self.players = {'primary': Player()}
        self.enemies = {}
        taskMgr.add(self.update,"update-whole-game")

    def update(self,task):#get size, update size if it changes, but update that here
        dt = globalClock.getDt()

        for player in self.players.keys():
            taskMgr.add(self.players[player].update, f'update-{player}',extraArgs=[dt],appendTask=True)

        task.cont

if __name__ == "__main__":
    game = Game()
    game.run()

And GameObject looks like this:

class Player():
    def update(self,dt,task):
        print("hey one thousand times")
        task.done

From what I understand, in this code, it should print "hey one thousand times" quite a few times as it's continually being called. Why is Player.update() only being called once?

mousetail
  • 7,009
  • 4
  • 25
  • 45
jfa
  • 1,047
  • 3
  • 13
  • 39
  • 1
    What do you expect `task.cont` to do? – Tim Roberts Aug 11 '23 at 05:57
  • 1
    With something like `task.cont` and `task.done`, it looks like you're try to call a function or method, but without parentheses (`()`), you're just accessing the function as a value, not calling it. You probably meant `task.cont()` and `task.done()` - if those are the correct methods to use there. – Grismar Aug 11 '23 at 05:58
  • @Grismar https://docs.panda3d.org/1.10/python/programming/tasks-and-events/tasks task.done and task.cont are called without parens – jfa Aug 11 '23 at 06:04
  • @TimRoberts Shouldn't it call update again repeatedly? – jfa Aug 11 '23 at 06:04
  • @TimRoberts my bad, I keep getting panda3d and pandas mixed up – jfa Aug 11 '23 at 06:05
  • 2
    @jfa According to the example you should *return* `task.cont`, only accessing the value will have no effect – mousetail Aug 11 '23 at 06:08
  • @mousetail wicked, good catch mate. – jfa Aug 11 '23 at 06:12
  • @jfa How do you call **any** function without parentheses? – DarkKnight Aug 11 '23 at 06:16
  • @DarkKnight If the function has an `@property` annotation then accessing it may already perform side effects – mousetail Aug 11 '23 at 06:24
  • @mousetail Then you're not explicitly calling a function - you're accessing a property – DarkKnight Aug 11 '23 at 06:28
  • @jfa yikes - thanks for looking it up though. The idea is that the descriptor value would be returned apparently, and not just sit there as if it was a call of sorts. – Grismar Aug 11 '23 at 21:15

0 Answers0