Boolean logic fail?

Hell all im working on a respawning AI function. only one problem, it doesnt respawn =/. heres the function. i can post full code if requested :slight_smile:

def fuckingtest(self, task):
        
        if self.AIisSpawned == False:
            self.loadAI()
            self.AIisSpawned = True
            self.shouldAddAICol = True
            
            return task.cont
        
    def updateAIPos(self, task):
            
        if self.shouldAddAICol == True:
            self.addCollision(self.ai)
            print 'adding ai col'
            self.shouldAddAICol = False
            
        if self.AIisSpawned == True:
            self.ai.setPos(self.ai,self.FORWARD*self.speed/10)
            
        if self.ailife <= 0:
        	self.ai.removeNode()
        	self.AIisSpawned = False
        	print 'ded'
        	return (self.AIisSpawned)
        	
        return task.cont

i tried printing all the booleans and they were all correct. its like after AIisSpawned is set back to false again it doesnt pick it up or something.

You are returning self.AIisSpawned when life is 0, since this is not a proper return value for a task, the updateAIPos task will not continue. You must return task.cont if you want the task to keep executing each frame.

im returning task.cont on both tasks, im confused?

What’s this then? :slight_smile:

        if self.ailife <= 0:
           self.ai.removeNode()
           self.AIisSpawned = False
           print 'ded'
           return (self.AIisSpawned) 

i added return task.cont and stil it doesnt work =/

I’m not sure if it’s a pasting error or not, but in the first function the task.cont should not be indented inside of the if statement, otherwise it will only be returned if the condition is true.

no it wasnt lol, i fixed that and it spawns a new ai after the first one dies but it doesnt add collisions to it or move it. ill have to fiddle with it