Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Why are loops and the attack command not working?


It gives me an error in python that i have to put () instead of loop:

1 Like

I also have this happening


You already killed the enemy, which is why it says it’s trying to read the position of null.

Edit: Never mind. You are right. for me hero.findEnemies() isn’t working.


As for loops, seems like they got broken somehow)


It’s just a weird way that codecombat is saying, it can’t find an enemy to attack so we are showing you a suggested replacement for it. IDK why they put the ducks in there. XD


Sorry for being off-topic, but why did you delete the ? after “User” in my title? @Chaboi_3000


No(twenty characters)


What do you mean “No”? Weren’t you the one who removed the question mark?


Seriously, I didn’t do it.
BTW I’ve got a painful stomachache today, so I might be off for a while


Okay. oof stomachaches suck


Guys I think I figured out what is going wrong. The hero.findNearestEnemy() would return the nearest person on the Ogres team, not on the enemy’s team (so if you are playing on Ogres team in multiplayer, this would return null)

cuz I tried my code for dueling ground as an ogre and it keeps saying attack has no target, but the same code works when I play as a human.


Use while True: instead of loop: now. loop: was an old CodeCombat-specific syntax construct we put in back when our transpiler required a workaround to make your code not infinitely loop when your loop was empty, but now we can do that inside the normal Python while True: loop, and recently I removed support for loop: (from which we had switched away in our sample code years ago).

Looks like loop has troubles