# Sorcerer's blitz need help

**URL:** <https://discourse.codecombat.com/t/sorcerers-blitz-need-help/30107>\
**Category:** Level Help\
**Created:** [August 20, 2021, 4:25pm UTC](https://discourse.codecombat.com/t/sorcerers-blitz-need-help/30107 "2021-08-20T16:25:41Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![lyrxq](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lyrxq](https://discourse.codecombat.com/u/lyrxq)\
**Post date:** [August 20, 2021, 4:25pm UTC](https://discourse.codecombat.com/t/sorcerers-blitz-need-help/30107/1 "2021-08-20T16:25:41Z")

</div>

Hi I’m confused on how this code works. Like it says it returns a list of enemy’s missile in air. So as it is a list, to specify a specific projectile, I need to use hero.findEnemyMissiles()[0], right? And if I have to find the type of the projectile, is it simply by adding the property ‘type’, like hero.findEnemyMissiles()[0].type?  
I don’t know why it seems my character couldn’t detect projectiles coming, and thus it doesn’t know when to cast a shield. ;(

My code for that part is like this:

```python
while True:
    if hero.nextSpawnDuration < 6:
        hero.spawnCollector()
    
    hero.findEnemyMissiles()
    
    if hero.findEnemyMissiles():
        if hero.findEnemyMissiles()[0]:
            if (hero.findEnemyMissiles()[0].type == "fire-ball") and (hero.canCast("water-shield")):
                hero.cast("water-shield")
            elif (hero.findEnemyMissiles()[0].type == "fire-beam") and (hero.canCast("water-shield")):
                hero.cast("water-shield")
            elif (hero.findEnemyMissiles()[0].type == "fire-arrow") and (hero.canCast("water-shield")):
                hero.cast("water-shield")
            elif (hero.findEnemyMissiles()[0].type == "water-ball") and (hero.canCast("earth-shield")):
                hero.cast("earth-shield")
            elif (hero.findEnemyMissiles()[0].type == "water-beam") and (hero.canCast("earth-shield")):
                hero.cast("earth-shield")
            elif (hero.findEnemyMissiles()[0].type == "water-arrow") and (hero.canCast("earth-shield")):
                hero.cast("earth-shield")
            elif (hero.findEnemyMissiles()[0].type == "earth-beam") and (hero.canCast("fire-shield")):
                hero.cast("fire-shield")
            elif (hero.findEnemyMissiles()[0].type == "earth-ball") and (hero.canCast("fire-shield")):
                hero.cast("fire-shield")
            elif (hero.findEnemyMissiles()[0].type == "earth-arrow") and (hero.canCast("fire-shield")):
                hero.cast("fire-shield")
        

```

How does this method actually work? Sorry if this is a stupid question ;3, cuz I am actually quite new to coding.

---

<div class="post-metadata">

**Author:** ![enPointe77](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/enpointe77/32/43632_2.png) [@enPointe77](https://discourse.codecombat.com/u/enPointe77)\
**Post date:** [August 20, 2021, 7:45pm UTC](https://discourse.codecombat.com/t/sorcerers-blitz-need-help/30107/2 "2021-08-20T19:45:46Z")

</div>

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](https://discourse.codecombat.com/t/essentials-how-to-post-format-your-code-correctly/15521?u)), or just hang out with other coders. But before you proceed, please check out our guidelines: [this topic.](https://discourse.codecombat.com/t/this-topic/15601)  
Have a great time! 🥳

---

<div class="post-metadata">

**Author:** ![lyrxq](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lyrxq](https://discourse.codecombat.com/u/lyrxq)\
**Post date:** [August 20, 2021, 8:18pm UTC](https://discourse.codecombat.com/t/sorcerers-blitz-need-help/30107/4 "2021-08-20T20:18:32Z")

</div>

Thanks for the welcome 😉

---

<div class="post-metadata">

**Author:** ![enPointe77](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/enpointe77/32/43632_2.png) [@enPointe77](https://discourse.codecombat.com/u/enPointe77)\
**Post date:** [August 20, 2021, 8:34pm UTC](https://discourse.codecombat.com/t/sorcerers-blitz-need-help/30107/5 "2021-08-20T20:34:16Z")

</div>

I can’t help you with this, but I can welcome you!

---

<div class="post-metadata">

**Author:** ![lyrxq](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lyrxq](https://discourse.codecombat.com/u/lyrxq)\
**Post date:** [August 20, 2021, 8:53pm UTC](https://discourse.codecombat.com/t/sorcerers-blitz-need-help/30107/6 "2021-08-20T20:53:55Z")

</div>

![image](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/5/0/50c453deacd41981255c65f4247c0e57be7f6278.png)

I have searched multiple forum posts about usage of this, and I see some people use this code on another arenas or levels I believe.

```python
hero.findNearest(hero.findEnemyMissiles())

```

It seems work for them, but somehow not for me. Why is it?  
Any help would be appreciated! :3

---

<div class="post-metadata">

**Author:** ![MarcusL123](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/marcusl123/32/23238_2.png) [@MarcusL123](https://discourse.codecombat.com/u/MarcusL123)\
**Post date:** [August 21, 2021, 11:14pm UTC](https://discourse.codecombat.com/t/sorcerers-blitz-need-help/30107/7 "2021-08-21T23:14:23Z")

</div>

Yes… I understand. There are no “enemyMissiles” so it can’t “find-Nearest”.  
Try making a variable for `hero.findEnemyMissiles` and put an `if variable:`.  
Put the `x = ...` and `if x and ...` code in the if statement

---

<div class="post-metadata">

**Author:** ![lyrxq](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lyrxq](https://discourse.codecombat.com/u/lyrxq)\
**Post date:** [August 23, 2021, 9:04am UTC](https://discourse.codecombat.com/t/sorcerers-blitz-need-help/30107/8 "2021-08-23T09:04:19Z")

</div>

Thanks Marcus, but still no luck

 ![image](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/c/3/c39015342d64173061084b75ddd3da4de1452352.png)

Shouldn’t the error message be ‘something is not defined’, if there are no enemyMissiles?  
I just can’t figure it out… so strange.

```python
enemyMissiles = hero.findEnemyMissiles()
    if enemyMissiles:
        nearestEnemyMissile = hero.findNearest(enemyMissiles)
        if nearestEnemyMissile:
            if nearestEnemyMissile and nearestEnemyMissile.mana == 'fire':
                hero.cast('water-shield')
            if nearestEnemyMissile and nearestEnemyMissile.mana == 'earth':
                hero.cast('fire-shield')
            if nearestEnemyMissile and nearestEnemyMissile.mana == 'water':
                hero.cast('earth-shield')

```

---

<div class="post-metadata">

**Author:** ![Aya](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/aya/32/42680_2.png) [@Aya](https://discourse.codecombat.com/u/Aya)\
**Post date:** [August 23, 2021, 10:23am UTC](https://discourse.codecombat.com/t/sorcerers-blitz-need-help/30107/9 "2021-08-23T10:23:21Z")

</div>

Welcome to the forum @lyrxq 🥳 Hope you enjoy your time here.  
You have that piece of code in a while true loop, right?

---

<div class="post-metadata">

**Author:** ![Aya](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/aya/32/42680_2.png) [@Aya](https://discourse.codecombat.com/u/Aya)\
**Post date:** [August 23, 2021, 10:29am UTC](https://discourse.codecombat.com/t/sorcerers-blitz-need-help/30107/10 "2021-08-23T10:29:59Z")

</div>

Also, you can make your code shorter by removing

> [@lyrxq](#):
>
> `nearestEnemyMissile and`

from each if statement inside this if statement:

> [@lyrxq](#):
>
> `if enemyMissiles:`

---

<div class="post-metadata">

**Author:** ![lyrxq](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lyrxq](https://discourse.codecombat.com/u/lyrxq)\
**Post date:** [August 23, 2021, 1:46pm UTC](https://discourse.codecombat.com/t/sorcerers-blitz-need-help/30107/11 "2021-08-23T13:46:30Z")

</div>

Thanks!

Yes, in a while-loop.

---

<div class="post-metadata">

**Author:** ![lyrxq](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lyrxq](https://discourse.codecombat.com/u/lyrxq)\
**Post date:** [August 23, 2021, 1:51pm UTC](https://discourse.codecombat.com/t/sorcerers-blitz-need-help/30107/12 "2021-08-23T13:51:32Z")

</div>

I see, thanks! I was just hoping to minimize errors here. But still, I have no idea why is this a type error. Isn’t it an entity? (Or is it how we call it idk)  
I have been struggling on this method like for these 2 days 😕

---

<div class="post-metadata">

**Author:** ![Aya](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/aya/32/42680_2.png) [@Aya](https://discourse.codecombat.com/u/Aya)\
**Post date:** [August 23, 2021, 5:53pm UTC](https://discourse.codecombat.com/t/sorcerers-blitz-need-help/30107/13 "2021-08-23T17:53:34Z")

</div>

Maybe the issue is from another part in the code, can u please post ur code?

---

<div class="post-metadata">

**Author:** ![lyrxq](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lyrxq](https://discourse.codecombat.com/u/lyrxq)\
**Post date:** [August 23, 2021, 6:45pm UTC](https://discourse.codecombat.com/t/sorcerers-blitz-need-help/30107/14 "2021-08-23T18:45:40Z")

</div>

Hmm I have opened a fresh new code to test this out and I would still get this ‘type’ error  
Here is my shortened version (cuz this is sort of a competition, I kinda not want to post my full code publicly) if you would like to try:

```python

def choose(collector):
    global count
    count += 1
    return ['fire', 'water', 'earth'][count % 3]

def collectHandler1(data):
    unit = data.target
    while True:
        if unit.isReady():
            unit.special()
        if unit.item:
            unit.bring()
        else:
            fruit = unit.findNearestFruit()
            if fruit:
                unit.pick(fruit)

def collectHandler2(data):
    unit = data.target
    while True:
        enemy = unit.findNearestEnemy()
        if enemy:
            if unit.distanceTo(enemy) < 5:
                unit.speical()
        else:
            unit.move(enemy.pos)

def collectHandler3(data):
    unit = data.target
    while True:
        fruit = unit.findNearestFruit()
        if fruit:
            if unit.distanceTo(fruit) > 5:
                unit.move(fruit.pos)
        else:
            unit.special()

def collectHandler4(data):
    unit = data.target
    while True:
        if unit.item:
            unit.bring()
        else:
            nearest = unit.findNearestEnemy()
            if nearest and nearest.item:
                if unit.distanceTo(nearest) < 5:
                    unit.special(nearest)
                else:
                    unit.move(nearest.pos)

def collectHandler5(data):
    unit = data.target
    fruit = unit.findNearestFruit()
    if fruit:
        if unit.item:
            if unit.distanceTo(fruit) > 5:
                unit.move(fruit.pos)
            else:
                unit.special(fruit)
                unit.bring()
        else:
            unit.pick(fruit)

        

hero.on('spawn-runner', collectHandler1)
hero.on('spawn-popper', collectHandler2)
hero.on('spawn-grower', collectHandler3)
hero.on('spawn-thief', collectHandler4)
hero.on('spawn-merger', collectHandler5)

spawndurationlimit = 10
while True:
    
    if hero.nextSpawnDuration <= spawndurationlimit and hero.health > 350 and hero.time < 130:
        hero.spawnCollector()
    
    if hero.health < 450:
        spawndurationlimit = 3
    
    enemyMissiles = hero.findEnemyMissiles()
    if enemyMissiles:
        nearestEnemyMissile = hero.findNearest(enemyMissiles)
        if nearestEnemyMissile and nearestEnemyMissile.mana == 'fire':
            hero.cast('water-shield')
        if nearestEnemyMissile and nearestEnemyMissile.mana == 'earth':
            hero.cast('fire-shield')
        if nearestEnemyMissile and nearestEnemyMissile.mana == 'water':
            hero.cast('earth-shield')
    

```

---

<div class="post-metadata">

**Author:** ![lyrxq](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lyrxq](https://discourse.codecombat.com/u/lyrxq)\
**Post date:** [August 23, 2021, 6:50pm UTC](https://discourse.codecombat.com/t/sorcerers-blitz-need-help/30107/15 "2021-08-23T18:50:04Z")

</div>

Don’t know if `hero.findNearest()` works with enemyMissiles, since it keeps popping out such ‘type’ error. I have also tried specifying the object with array on `hero.findEnemyMissiles()`, assuming the least value of the index in the list would be the closest to the hero. Still no luck (you can refer to the first post).

---

<div class="post-metadata">

**Author:** ![MarcusL123](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/marcusl123/32/23238_2.png) [@MarcusL123](https://discourse.codecombat.com/u/MarcusL123)\
**Post date:** [August 27, 2021, 1:09am UTC](https://discourse.codecombat.com/t/sorcerers-blitz-need-help/30107/16 "2021-08-27T01:09:43Z")

</div>

I figured it out! You know, the balls/ arrows/ beams goes fast, right? So when you cast the shield, CoCo can’t find it again.Please also hover over the “!” and take a picture with it. it will say something different, I think.

---

<div class="post-metadata">

**Author:** ![lyrxq](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lyrxq](https://discourse.codecombat.com/u/lyrxq)\
**Post date:** [August 27, 2021, 1:32am UTC](https://discourse.codecombat.com/t/sorcerers-blitz-need-help/30107/17 "2021-08-27T01:32:57Z")

</div>

A bit confusing for me. What does CoCo mean?

For me, I think there shouldn’t be any significant delay in the if statement, even though they do travel fast, as those if operations are done within milliseconds, right? 🤔(I don’t know if that’s how we call the whole thing)

Apparently I see some top leaderboard players being able to cast a shield when a projectile is coming. Most others don’t. I’m beginning to think they could be tracking the opponent’s hero mana to determine if earth/water/fire balls are casted. Hope that’s not the case, else this is so braindead like how come a method dedicated to detecting projectiles not working or idk being so non-user friendly.

I will go and check on the exclamation mark to see what it says. Wait me a moment.

---

<div class="post-metadata">

**Author:** ![lyrxq](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lyrxq](https://discourse.codecombat.com/u/lyrxq)\
**Post date:** [August 27, 2021, 1:41am UTC](https://discourse.codecombat.com/t/sorcerers-blitz-need-help/30107/18 "2021-08-27T01:41:45Z")

</div>

![image](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/c/6/c6933a0b24ae0a1b32ce5a7390ff891435bf7961.png)  
Sadly, it remains the same

---

<div class="post-metadata">

**Author:** ![enPointe77](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/enpointe77/32/43632_2.png) [@enPointe77](https://discourse.codecombat.com/u/enPointe77)\
**Post date:** [August 27, 2021, 3:59am UTC](https://discourse.codecombat.com/t/sorcerers-blitz-need-help/30107/19 "2021-08-27T03:59:12Z")

</div>

> [@lyrxq](#):
>
> CoCo

CoCo is just the abbreviated version of CodeCombat.

---

<div class="post-metadata">

**Author:** ![unityjoaquimschaever](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/unityjoaquimschaever/32/24157_2.png) [@unityjoaquimschaever](https://discourse.codecombat.com/u/unityjoaquimschaever)\
**Post date:** [August 27, 2021, 7:57am UTC](https://discourse.codecombat.com/t/sorcerers-blitz-need-help/30107/20 "2021-08-27T07:57:17Z")

</div>

Try making your own nearest method

---

<div class="post-metadata">

**Author:** ![lyrxq](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lyrxq](https://discourse.codecombat.com/u/lyrxq)\
**Post date:** [August 27, 2021, 6:33pm UTC](https://discourse.codecombat.com/t/sorcerers-blitz-need-help/30107/22 "2021-08-27T18:33:15Z")

</div>

I tried before, it does work without any errors, but same it doesn’t seem to be able to findEnemyMissiles.

Off-topic: summer is ending and i still got loads of homework hehe. Since I have already invested quite much time in coding and I’m satisfied with my rank and what I have learnt, so maybe I might take a break, thanks everyone here! Very heart-warming community 🥴

[Next page](https://discourse.codecombat.com/t/sorcerers-blitz-need-help/30107.md?page=2)
