Problem with LerpFunc

I am going through the “Panda 1.7 Developer’s Cookbook”.

On page 52 I followed the following code:

from direct.interval.LerpInterval import LerpFunc

def someFunc(t):
    print t

fn = LerpFunc(someFunc, fromData = 0, toData = 1, duration = 10)
fn.start()

…and I get the following error:

Is this a bug in Panda or have I been grossly naive in my implementation of the code snippet? If so, can anybody enlighten me please?

Many thanks!

I’ve personally never seen that error message before, but giving the “-O” option to python/ppython should get rid of it.

You get that error message when you create a LerpFunc before you have created a ShowBase instance (for instance, by inheriting from ShowBase, or by importing DirectStart).

David

Thanks drwr.

I edited the code to this and it worked:

from direct.showbase.ShowBase import ShowBase
from direct.interval.LerpInterval import LerpFunc

class SomeClass(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)
        fn = LerpFunc(self.someFunc, fromData = 0, toData = 1, duration = 10)
        fn.start()

    def someFunc(self, t):
        print t

myTest = SomeClass()
myTest.run()

Does everything have to be wrapped in a class inheriting from ShowBase?

No, but you generally need to have created exactly one ShowBase instance for most of the Panda tools to work well. ShowBase is responsible for most of the low-level set up of Panda, so if you don’t create a ShowBase, a lot of stuff is not yet initialized.

But you don’t want to make everything inherit from ShowBase, because it’s important that there is only one ShowBase instance in your application. If you create a second ShowBase, you get other kinds of problems.

David

Thanks again David!

Ah! OK, I think I understand. It’s not a ‘god’ object but you do need one, and only one.

So I take it that ShowBase is essentially the ultimate container within which the game takes place - i.e. the thing that holds the scene-graph?

You can think of it that way, though really it’s a bit less structured than that. Technically there’s no real reason to require a ShowBase object, except that there’s a fair amount of already-existing code that does assume it exists.

Still, the ShowBase object is the container for a lot of low-level Panda objects, including render (the scene graph) and most importantly, the igloop task, which is where the drawing actually happens.

David