it says my code has an infinite loop. my code:
while true:
if hero.isReady(‘heart-shield’):
hero.heartShield()
else:
hero.shield()
if hero.gold >= 25:
hero.buildXY(“decoy”, hero.pos.x, hero.pos…y)
and when I do comment out of my code, my hero does nothing
Welcome to the forum! This is a family-friendly place where coders can share bugs, ask for help on any CodeCombat level (don’t forget to post your code correctly), or just hang out with other coders. But before you proceed, please check out our guidelines: this topic.
Have a great time!
i think your if hero gold should be below if hero is ready
Please don’t forget to format your code properly using this button:
This time I formatted it for you:
while true:
if hero.isReady(‘heart-shield’):
hero.heartShield()
else:
hero.shield()
if hero.gold >= 25:
hero.buildXY(“decoy”, hero.pos.x, hero.pos…y)
I can see several mistake here
- in the while true loop, the “true” should be capitalized:
while True:
- In your build statement, the third argument - y - should be
hero.pos.y
instead ofhero.pos...y
- You might want to place the if statement of the building decoy at the beginning
I did that but it still says infinte loop
Hi @Aya , I did that but It still say my code has an infinite loop
Can you please post your newest code
I CAN’T enter the level
Oops, how come?
20chars
It says Infinite loop detected @Aya
You can press “comment out my code”, and sorry for the late reply
I still does not work @Aya
is this kithgard brawl 8 or smthn? cuz if its that then the problem might just be way too many units so It bugs out
I know it is the problem @cheddarcheese but I can’t fix it
no one can fix it not even me
I hope someone will remove some ogres
No, it shouldn’t.
Maybe someone should remove some ogres
Create a function called whatever you want (e.x: do)
So do something like:
def do (b):
while True:
if hero.isReady(‘heart-shield’):
hero.heartShield()
else:
hero.shield()
if hero.gold >= 25:
hero.buildXY(“decoy”, hero.pos.x, hero.pos.y)
Then add
if b: return
to the start of the function.
And then add
hero.wait(0)
do(True)
to the end of the while loop. That should trick the ‘infinite-loop’ error.