Your if enHero block always returns, regardless which part if it executes. Returning from a function skips the rest, which means everything below that if-statement is unreachable. The result is enFire, enWater, and enEarth are always 1.
can you command collectors to move to the place I want them to go?
As goutham123 said, you can assign a function to hero.chooseItem that returns a position. The collector the function was run for will seek out the fruit nearest to that position.
Hi Hydrobolic,
I would like help on some code.
In my “while True” loop, when I do
enemy = hero.getEnemyHero()
shield = enemy.getActiveShield()
My character just waits for the enemy to create a shield.
Can you help? Is there a way to fix this?
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!
Your code shouldn’t block on finding the enemy’s shield, so you should be able to proceed with normal attack code regardless of whether the enemy has a shield or not. I’m not quite sure what your question is. Perhaps on how to structure your program?
enemy = hero.getEnemyHero()
while True:
shield = enemy.getActiveShield()
if shield:
pass # The enemy has a shield! Let's counter it!
else:
pass # The enemy doesn't have a shield, so let's attack normally.
Okay, thanks!
I did this and I think it works.
Here’s a snippet:
while True:
if shield and shield.mana == "fire" and not hero.canCast("water-ball"):
while shield and shield.mana == "fire" and not hero.canCast("water-ball"):
hero.cast("water-arrow")
elif shield and shield.mana == "water" and not hero.canCast("earth-ball"):
while shield and shield.mana == "water" and not hero.canCast("earth-ball"):
hero.cast("earth-arrow")
elif shield and shield.mana == "earth" and not hero.canCast("fire-ball"):
while shield and shield.mana == "earth" and not hero.canCast("fire-ball"):
hero.cast("fire-arrow")
A tick is a tenth of a second. You can always while True: print(hero.time) and inspect it in the console.
I believe the three if statements in your snippet are not necessary, as each while-loop will be skipped if its condition is not met. Also, make sure you call enemy.getActiveShield() again as necessary. Your reference to shield won’t automatically update.
oldfire = enemy.fire
oldwater = enemy.water
oldearth = enemy.earth
i = 0
while i<5:
i+=1
if oldfire>enemy.fire+5:
hero.cast("water-shield")
if oldwater>enemy.water+5:
hero.cast("earth-shield")
if oldearth>enemy.earth+5:
hero.cast("fire-sheild")
It is not working. Can you help?
This is in my while loop.
hi, ik this is dead post but i still need some help
is there a way to tell what spells the enemy casts so i can use shields before they hit me? or do i have to defeat them before they defeat me lol
hero.findEnemyMissiles() finds all the current missiles flying towards you, so you could use that, I’ll give you a snippet of my code that I created 2 years ago (it got me to top 10 in all age groups, and top 1 in my age group)
let ms = hero.findEnemyMissiles();
if (ms.length > 0) {
let m = ms[0];
if (m.pos.x < (m.maxSpeed * 2.1) || (hero.time > 120 && m.type !== m.mana + "-arrow")) { // checking if it's about to hit me
if (m.type !== m.mana + "-arrow" || hero.time > 120) { // checking if it's not an arrow
let aS = hero.getActiveShield();
// checking if active shield works, if not, new shield
}
}
}