I can't stop a interval

def enterAdvance(self):
	self.avatar.play('walk')
	# 使用间隔移动
	self.inte = Sequence(LerpPosInterval(self.avatar,duration=0.4,pos=(0,-0.002,0),other=self.avatar), Func(self.request,'Stand'),name='Advance')
	self.inte.start()
def exitAdvance(self):
	self.inte.finish()

When I try to finish interval that called ‘Advance’, it tell me

Exception occurred while processing Func-request-1 of Advance:
Advance:
  0.000 Advance {
  0.000   LerpPosInterval-1: pos from 0 0 0 to 0 -0.002 0 dur 0.4
  0.400   *Func-request-1
  0.400 }

Then the code crash.

I user pause instead of a finish .

I am not sure what’s causing this. Panda3D’s error messages are not terribly precise when it comes to intervals or sequences. But I notice a few things in your code:

  • I am not sure if it’s a good idea to give your interval a name. That makes the interval unique. If an interval with the same name is started, the old one finishes automatically. Calling finish on that old interval might produce errors.
  • You set other to be self.avatar, which is also the node that the interval performes on. That makes the interval relative to itself, which is not recommended (see the manual).
  • You are requesting a new state directly (request(“Stand”). Maybe you are using the old FSM instead of the new one? With the new one it would be something like request(“to_stand”) and then you would use the filter function of your current state to determine if to go to the “Stand” state.

When you call finish() (instead of pause()), it finishes the sequence meaning that it also calls the Func at the end, so it calls self.request(‘Stand’) while you’re still in exitAdvance. I’m not sure, but I don’t think it’s valid to change states in an FSM exit method.

Thank you very much!

  • Now I use “name=‘Advance’+self.name” instead “name=‘Advance’”.

  • I will change it:

self.seq = Sequence(LerpPosInterval(self.avatar,duration=0.4,pos=self.avatar.getPos()+(-0.3,0,0)), Func(self.request,'Stand'),name='Advance'+self.name)
  • Actually, my code is:
######## 向前迈步
def filterAdvance(self, request, args):
	if request == 'Stand': # 站立
		return 'Stand'
	elif request == 'lightboxing': # 轻拳
		return 'LightBoxing'
	elif request == 'straight': # 再次按前进
		return 'Run'
	elif request == 'Bodycollide': # 发生碰撞后要后退一点
		return 'Backlittle'
	elif request == 'Beaten': # 被打到了
		return 'Beaten'
	else:
		return None

Sorry, I admit this code is very bad, I will modify later.

I envisioned:

play and move it.
if (after 0.4 seconds) :
    request('Stand')
if (press other keys) :
    finish the move and stop at the current position
    request('Stand')

[/code]