Noob question on loops

Hello, I am new here, and somewhat new to panda3d as well. Anyway I have worked in pygame before and it seemed that loops were pretty standard fare for making games with it, yet so far all of the examples I have seen for Panda3D have shown a consistent lack of loops, and in stead seem to use something like the

        return Task.cont

statement at the end of a “world” class to get the same results. The thing is that most programming that I have experience in revolves around using loops to handle user input, and so it is one of the standard tenets of how I plan out programs, so getting rid of the loop as the basic foundation of an interactive program would take some getting used to. So is there a reason not to use a loop for a panda3d script?

thanks in advance

The task system is kind of like loops, but it allows you more control. You can schedule a task that repeats every frame, or every few seconds, and so on. Tasks also let you set priorities, so you can determine in which order they are run each frame.

Panda does run in a loop, it is started by calling “run()” and any tasks you have defined will be executed as a result of this main loop. If you want you could just create one task and put all of your game logic inside of that, but I think you’ll come to appreciate the power that the task system affords you.

Have a read through the manual for all the juicy details.

This is not only a great benefit of Panda as teedee said, but also a trend game programmers will have to become comfortable with. Multiple processor cores leads to more threading and a general need to perform tasks in an asynchronous manner to take full advantage of hardware. Even without threading there’s a lot of things you don’t want to run every frame. Sticking everything in one big while loop may be simple and comfortable, but the further you take a game, the more you’ll wish for something just like Panda’s task system.

If you really want, though, replace your run() call with this:

while True:
  # Do whatever you want here
  
  # Advance the task manager one frame,
  # to perform the rendering tasks etc
  taskMgr.step()

But yeah, I really recommend using tasks. It’s not much different, but much more flexible.

Ok, thanks for the replies, I guess I’ll have to get used to it.

A quick question though, as I recall pygame used the “clock” function to set a standard speed for a game, what is the panda equivalent? And is it only good for loops or does it work with tasks too?

Use the global clock if you want to know how much time has passed. For example if you want to move an object 5 units per second you would multiply the time the last frame took to render by 5 to find out how far to move it.
http://www.panda3d.org/manual/index.php/The_Global_Clock