Why does ''target is null'' display to me?


#1

Hi,
I’m on level Backwoods Brawl, and every time, when I attack, I get a message saying ‘‘target is null’’. I’m using this:

enemy = self.findNearestEnemy()

loop:
    if self.isReady("power-up"):
        self.powerUp()
    else:    
        self.attack(enemy)          
        self.attack(enemy)

Can somebody help me?


#2

you are setting enemy OUTside the loop…(so it never changes)


#3

please edit your code like this

code
some more code

if you are looking for several enemies u have to find the enemy iside the loop.
there is not everytime an enemy, use if/else to define what u do.

there are several posts in this forum about the same problem… if you would have searched u would have found a reason…
Try this…


#4

@bmmtstb

like this

is not very helpful. I contacted AdsmeGames how to do it properly. The easiest way to show this to someone in the future is to simply point them to the FAQ.


#5

Another quick problem is that you are not checking if an enemy exists before you attack it