.getcolor() error

ok so i use .setcolor() to set a highlight color this works well but when its no longer hightlighted i wanted to clear the color so i did this:

            for i in range(len(self.actorLoad.InnerSphere)):
                self.xA1 = self.actorLoad.InnerSphere[i].getX()
                self.yA1 = self.actorLoad.InnerSphere[i].getY()
                if self.xA1 < self.Mouseload.bigX and self.xA1 > self.Mouseload.smallX and self.yA1 < self.Mouseload.bigY and self.yA1 > self.Mouseload.smallY:
                    self.actorLoad.InnerSphere[i].setColor(self.HIGHLIGHT)
                else:
                    if self.actorLoad.InnerSphere[i].getColor() == self.HIGHLIGHT:
                        self.actorLoad.InnerSphere[i].clearColor()

So what this should do is get the mouse points compare the actors to them if there within the mouse points then highlight them else check if there highlighted and unhighlight them. I didnt have the check if highlighted before and the game would crash as you cannot remove whats not there. but if the actor isnt highlighted it just skips the if statement and does the next line and crashes anyway. keep in mind it only does this if there is more than 1 innersphere actor as in order to get the code to fire in the first place one actor must be in the highlighted section. what can i do maybe a different way to highlight that will work better or a different if statement to see if getcolor is false although i dont know how to do that.

I don’t know what you mean. You can call clearColor() on any valid NodePath, it won’t crash as long as the NodePath itself isn’t empty, whether or not it already has a color set.

David

Well im getting an error in Panda when I run the code without checking the if statement first. But of course the if statement is faulty too. I cant say what the error is right now as I am at work but i will post it when i get home

Ok I managed to fix the issue it was with setcolor and getcolor but with other things at the same time that caused a problem which is now fixed.

New problem:

When I want to check my char using the below code it always fires even if the setcolor() dosnt match. Maybe i shouldnt use this but its the ony way i currently know its highlighted can someone tell me why this is doing this?

            for i in range(len(self.highlighted)):
                    if self.highlighted[i].getColor() == self.highlightinfo:
                        self.AI[i].pathFindTo(self.pointer, "addPath")

needed info: my actor always has a setcolor on but not self.highlightinfo it only has this if its highlighted b my highlight code and cleared on the next draw if not within the mouse pointer info.

I don’t see any problem with that code. Are you sure the setColor doesn’t match?

David

yes the set color dosnt match but i figured out the problem in that if they were still in the highlghted area even after it is no longer highlighted they still got a pass on a check so they skipped that check lol then they were still working when they shouldnt. Thanks for your help david though as i dont think i would have figured it out unless you posted my code is right lol