Misspelling, the ultimate archenemy of coding!!
Finally got to the desert phase. Pretty stoked. Doing this all in conjunction with W3 and Free Coding Camp (and a few other resources) is extremely helpful.
ââŚhow do I see about how many enemies are there?â
You donât need (any) glasses to have access to some functions in any CoCo level.
So the answer for the last enemy wave will be 10 ogres and 2 catapults:
console.log('count enemies:' + hero.findEnemies().length);
// console: count enemies:12
Itâs funny I read recently for the first time the hints and noticed there is a âmagic kill them all buttonâ :-). Till then i had the third bonus being in good health but with no time left to succeedâŚ
Ready to swap my code with anyone who has all four bonuses.
Can you guys help me, Iâve been working on this for much longer than I care to admit. For some reason, the game doesnât register the enemy as a target and would stop reading at âenemy = hero.findNearestEnemy()â
while True:
enemy = hero.findNearestEnemy()
if enemy:
LightningSpam
#this is a defined function
elif hero.canCast(âregenâ):
hero.cast(âregenâ, hero)
else:
hero.moveXY(8, 43)
Hi @John_Moone, welcome to the CodeCombat Discourse.
I think whatâs stopping your code is this line:
If you want to call a function you need to use brackets ().
Please could you post all your code, formatted:
And then Iâll be able to help you more.
It may also be something to do with hero.debug(), Iâm not sure thatâs actually a method and it may be causing the error.
Thanks
Danny
Blockquote
If you want to call a function you need to use brackets ().
Please could you post all your code, formatted:
Youâre right. Sorry, Iâm a complete beginner in coding (and forums). I did a little double-checking and found that I also turned enemy into a string (âenemyâ) when I defined it. Iâve also removed debugging. Thanks a lot!
This is my code now, it still doesnât solve the puzzle but I plan on coming back to this after I finish the other levels so Iâm likely to redo it completely some other time.
# Defeat as many ogres as you can.
# Use 'cast' and 'canCast' for spells.
def LightningSpam(target):
if enemy:
if hero.canCast ("lightning-bolt"):
hero.cast("lightning-bolt", "enemy")
elif hero.canCast("chain-lightning"):
hero.cast("chain-lightning","enemy")
elif hero.canCast("Root"):
hero.cast("Root","enemy")
pass
while True:
enemy = hero.findNearestEnemy()
if enemy:
LightningSpam
#this is a defined function
elif hero.canCast("regen"):
hero.cast("regen", hero)
else:
hero.moveXY(8, 43)
Hi, did you mean to leave this line as it was:
This is the line I meant when I said you needed ().
E.g.
def attackEnemy():
enemy = hero.findNearestEnemy()
if enemy:
if hero.isReady("bash", enemy):
hero.bash(enemy)
else:
hero.attack(enemy)
while True:
attackEnemy() # you need the two brackets at the end
âLightningSpam()
I hope this helps,
Danny
Hi,
not sure if anyone reading this still. But I am about to get into some programing skills, because my Network skills aren´t enough for todays world. I am also about to get into some Linux and deeper python skills, so if you guys have something where I can learn (meaning recommendations) it would be great.
I am coming here with request about the catapult.
I have built up the code for now until the catapult comes on scene and I am not sure why, but the hero does not sees him
Can someone help me (little hint) why? Why I don´t âenemy = hero.findNearestEnemy()â catapult?
thanks guys for help.
Regards,
Tomas
Summary
catapult = "catapult"
while True:
enemy = hero.findNearestEnemy()
if enemy:
if hero.isReady("chain-lightning"):
hero.cast("chain-lightning", enemy)
elif enemy.type == "catapult":
hero.moveXY(9, 30)
hero.cast("lightning-bolt", catapult)
else:
hero.attack(enemy)
if not enemy:
hero.cast("regen", hero)
Edit:Sorry I am too lame and cannot pass it with âtabsâ dunno why
Hi there, @Tomas_Zima! Welcome to the CodeCombat Discourse.
Could you post your equipment(send a screenshot of what your hero is wearing)?
Thanks.
Rachel
Thank you for fast answer.
It is the mision with âChallenge The One Wizardâ
Thanks with best regards
Hey @Tomas_Zima, please go through the link to understand the rules. Also, try finishing the discobot tutorial.
Hello and welcome to codecombat discourse! This is a cozy forum where you can share ideas, share fan art, get assistance for code, etc! Before you proceed, we hope that you review this topic, which shows all essentials of this board! Thanks!
P.S. i have no clue about the catapult, i just spammed the lightning and regen spells.
Could you show an image of the error or when youâre hero dies/teleports?
Hi Ashmit,
sorry if i typed something Wrond.
Do you mean the âblueâ page at top of the website?
I will go through and thank you for reminding.
And also thank you for your hint
yeah, youâre welcome, also, i think you used the chinese ââ so it wont work. Iâm not sure
Oh yeah, like @Ashmit_Singh said, it looks like youâre using Chinese Quotation marks, instead of the quotation marks the system recognizesâŚ
Though we canât be sure. Could you format your code using the </> button?
Thanks
Ah I seeâŚ
I used only this =>
I am having trouble with that when the catapult appears on scene my hero does nothing (or maybe regen) but does not detect the catapult at all, or at least, it seems to me
Hm. I donât see anything wrong with your code
Maybe @milton.jinich, @Deadpool198, @xython, @abc and/or @Falcons118 could help, sorry
Rachel
its the regen!! regen cancels all movements and actions for the time being, thats why my code only uses it when im below 50 hp
Hmm⌠to find a specific type of enemy, you would do
catapult = hero.findNearest(hero.findByType("catapult")
Just replace catapult with the type of enemy or friend you want to find.
Lydia
Hi Lydia,
it is mess in the code I will burn it, it was trying to âspecifyâ catapult at all, because I didn´t know how to specify it at all, once I âkilledâ it after hero âdiedâ I knew, and forget to delete this line. But thank you for hint
I used var, because I didn´t know about if enemy.type " "
Aha, didnât see that regen do smthin like this, I should read more prblby⌠Thanks much, I will try to fix my code and do better next time