LerpPosInterval() question

I think I’m misunderstanding something fundamental to how PosIntervals work. I’m reading the documentation (actually it’s the documentation for LerpPosInterval, but my understanding was that they are the same), and I see a couple bits that seem contradictory to me:

In the section explaining the startPos parameter:

OK, sounds useful. But then the next bit says:

So… It’s been a while since I’ve worked with Python, so maybe that’s what I’m misunderstanding, but… My confusion is that the first quote seems to say that if you pass a function as the startPos parameter, the function won’t get called until the interval actually begins playing. But the second quote seems to give an example of a function being passed as the startPos parameter, and then says that it will be called when the interval is created, not when it begins playing.

Now, looking at an example like

my_interval = nodePath.posInterval(3, this_function(), that_function(), etc)

I would normally expect those functions to get called when my_interval is created, not when the interval starts playing, just as in any other Python code. But given that, I’m not sure what the first quote up above is trying to say. I thought maybe it meant you could pass in a reference to a function like

def a_function(param):
	return something

ref = a_function

my_interval = nodePath.posInterval(3, ref, etc...

But when I try that, the function never gets called.

What am I missing here? And how can I create a posInterval that has different, programmatically generated pos and startPos values every time it plays? I can get the effect I’m looking for by creating the interval anew every time I want to play it, but that feels wasteful.

Looking at the example in the second quote that you give, note the brackets: it doesn’t show a method being passed in – it shows a method being called and the result being passed. In order to pass the method itself in, I believe that the example would be changed to something like this:

startPos=object.getPos # Note the lack of brackets

In your example, I’m not sure of why the function isn’t being called – that does look like what the first quote is suggesting. Perhaps the problem is the type: I see that the manual page specifies that it should return a Point3; if your code is returning a Vec3, for example, the code that it gets passed to might be ignoring the result.

Yeah, that’s what I thought it meant, too. No, the function definitely returns a Point3. I guess maybe I can refocus my question like this: Why are functions I pass as the pos or startPos parameters of posInterval() never getting called?

Here’s a condensed example:

self.pointer = self.loader.loadModel("pointer") 		#this is just a sphere
self.pointer.setScale(1, 1, 1)
self.pointer.setPos(5, 5, 5)

self.lerp = self.pointer.posInterval(3, pos = self.get_step_y, startPos = None
				, other = None, blendType = "easeInOut", bakeInStart = 0, fluid = 0, name = "lerp")

def get_step_y(self):
	print("calling get_step_y")
	return Point3(self.pointer.getX(), self.pointer.getY() + 1, pointer.getZ())

When I play the “lerp” interval, not only does the “pointer” model not move, but the print statement in get_step_y() never appears in the console. I know the interval is playing, though, because of some other test print statements that only appear if self.lerp.isPlaying() == True. I still feel like I’m not understanding something about how this works.

I’m not sure why, but I got this to work simply by enclosing the interval in a Sequence and calling start() on the sequence instead. I don’t know too much about the interval system, but it’s possible you’re meant to do this.

Well I’ll be… That sure did work. I don’t understand why, but then that’s not very surprising. Thanks, Tober!

I never would have thought to do that, particularly since I knew nothing about Sequences yet. I normally like to feel like I understand one thing fully before moving on to the next… I would, of course, still be interested to find out why this is (or even just have somebody authoritatively say “that’s the way it was meant to be used”) if anyone who knows happens to read this.

Wow, that really is weird. o_0

Until someone with more in-depth knowledge on the subject responds, the conjecture that comes to my mind is that perhaps the function-handling logic is for some reason handled in Sequence; perhaps within Sequence there is code that checks the current interval for function references, and, if they are found, executes them and replaces the reference with the result (presumably either storing the reference for further use or creating a copy of the Interval to run).