# Level "Taunting" \[LUA\]

**URL:** <https://discourse.codecombat.com/t/level-taunting-lua/37480>\
**Category:** Level Help\
**Created:** [May 5, 2024, 10:20am UTC](https://discourse.codecombat.com/t/level-taunting-lua/37480 "2024-05-05T10:20:31Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stroogles](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@Stroogles](https://discourse.codecombat.com/u/Stroogles)\
**Post date:** [May 5, 2024, 10:20am UTC](https://discourse.codecombat.com/t/level-taunting-lua/37480/1 "2024-05-05T10:20:31Z")

</div>

no errors, but my hero simply won’t attack, went through other forums, and found someone with the same issue who simply reloaded a bunch of times, and one who switched heros, neither of which have worked for me

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

---

<div class="post-metadata">

**Author:** ![Stroogles](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@Stroogles](https://discourse.codecombat.com/u/Stroogles)\
**Post date:** [May 5, 2024, 10:21am UTC](https://discourse.codecombat.com/t/level-taunting-lua/37480/2 "2024-05-05T10:21:23Z")

</div>

```python
function dealEnemy(enemy)

    if enemy.type == "munchkin"

   then self:attack("munchkin")

    if enemy.type == "brawler"

     then self:say("come here!")

while true do
    local enemy = hero:findNearestEnemy()
    if enemy then
        dealEnemy(enemy)
    else
        hero:moveXY(30, 34)
    end
end
    end
end
end

```

---

<div class="post-metadata">

**Author:** ![MarmiteOnToast](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/marmiteontoast/32/46649_2.png) [@MarmiteOnToast](https://discourse.codecombat.com/u/MarmiteOnToast)\
**Post date:** [May 5, 2024, 10:32am UTC](https://discourse.codecombat.com/t/level-taunting-lua/37480/3 "2024-05-05T10:32:55Z")

</div>

Hi @Stroogles, welcome to the Discourse! Thanks for formatting your code.

I don’t know Lua, but there are a few issues that I can help you with:

> [@Stroogles](#):
>
> `self:attack("munchkin")`

The munchkins are not all called “munchkin”, yet you used a string. Since you want to attack them, use `enemy` (without quotation marks/inverted commas) in place of `"munchkin"`

You’re also missing `end` at the end of both `if` checks in the `dealEnemy` function, and have redundant `end` keywords after the `while True` loop.

---

<div class="post-metadata">

**Author:** ![Stroogles](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@Stroogles](https://discourse.codecombat.com/u/Stroogles)\
**Post date:** [May 5, 2024, 10:54am UTC](https://discourse.codecombat.com/t/level-taunting-lua/37480/4 "2024-05-05T10:54:17Z")

</div>

function dealEnemy(enemy)

```
if enemy.type == "munchkin"

```

then self:attack(enemy)  
end  
if enemy.type == “brawler”

```
 then self:say("come here!")

```

end  
while true do  
local enemy = hero:findNearestEnemy()  
if enemy then  
dealEnemy(enemy)  
else  
hero:moveXY(30, 34)  
end  
end  
end

yields the same results, a little confused what you’re trying to get at with the munchkin thing but I tried, though “munchkin” should already be labled as a specific enemy type, and something similar worked in the last level.

---

<div class="post-metadata">

**Author:** ![Stroogles](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@Stroogles](https://discourse.codecombat.com/u/Stroogles)\
**Post date:** [May 5, 2024, 10:54am UTC](https://discourse.codecombat.com/t/level-taunting-lua/37480/5 "2024-05-05T10:54:55Z")

</div>

forgot to format correctly

```python
function dealEnemy(enemy)

    if enemy.type == "munchkin"

   then self:attack(enemy)
end
    if enemy.type == "brawler"

     then self:say("come here!")
end
while true do
    local enemy = hero:findNearestEnemy()
    if enemy then
        dealEnemy(enemy)
    else
        hero:moveXY(30, 34)
    end
end
end

```

---

<div class="post-metadata">

**Author:** ![MarmiteOnToast](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/marmiteontoast/32/46649_2.png) [@MarmiteOnToast](https://discourse.codecombat.com/u/MarmiteOnToast)\
**Post date:** [May 5, 2024, 11:28am UTC](https://discourse.codecombat.com/t/level-taunting-lua/37480/6 "2024-05-05T11:28:56Z")

</div>

Didn’t you receive this error?  
 ![image](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/b/c/bc86296c2e3754340e88894b832bd77999d7d8b4.png)

Also, try replacing the second `if` with `elseif`, remove the `end` on line 6, and add another `end` to the end of the function (at the moment you end the `if` loop, but not the function)

---

<div class="post-metadata">

**Author:** ![Stroogles](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@Stroogles](https://discourse.codecombat.com/u/Stroogles)\
**Post date:** [May 5, 2024, 11:35am UTC](https://discourse.codecombat.com/t/level-taunting-lua/37480/7 "2024-05-05T11:35:36Z")

</div>

no errors at all,

```python
function dealEnemy(enemy)

    if enemy.type == "munchkin"

   then self:attack("munchkin")
    elseif enemy.type == "brawler"

     then self:say("come here!")
end
while true do
    local enemy = hero:findNearestEnemy()
    if enemy then
        dealEnemy(enemy)
    else
        hero:moveXY(30, 34)
    end
end
end

```

still has the same results, no action (changed it back to (“munchkin”) example)

---

<div class="post-metadata">

**Author:** ![MarmiteOnToast](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/marmiteontoast/32/46649_2.png) [@MarmiteOnToast](https://discourse.codecombat.com/u/MarmiteOnToast)\
**Post date:** [May 5, 2024, 11:37am UTC](https://discourse.codecombat.com/t/level-taunting-lua/37480/8 "2024-05-05T11:37:01Z")

</div>

It’s weird that you aren’t getting any errors… Place a hero.say(“debug”) as the first action in the function to check if it’s running that

---

<div class="post-metadata">

**Author:** ![Stroogles](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@Stroogles](https://discourse.codecombat.com/u/Stroogles)\
**Post date:** [May 5, 2024, 11:39am UTC](https://discourse.codecombat.com/t/level-taunting-lua/37480/9 "2024-05-05T11:39:14Z")

</div>

tried using both hero:say and self:say, neither worked (nothing was said)

---

<div class="post-metadata">

**Author:** ![MarmiteOnToast](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/marmiteontoast/32/46649_2.png) [@MarmiteOnToast](https://discourse.codecombat.com/u/MarmiteOnToast)\
**Post date:** [May 5, 2024, 11:40am UTC](https://discourse.codecombat.com/t/level-taunting-lua/37480/10 "2024-05-05T11:40:02Z")

</div>

Oh, remember to add the second end to the function

correct me if I’m wrong, but you’re only ending the if/elseif at the moment

---

<div class="post-metadata">

**Author:** ![Stroogles](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@Stroogles](https://discourse.codecombat.com/u/Stroogles)\
**Post date:** [May 5, 2024, 11:40am UTC](https://discourse.codecombat.com/t/level-taunting-lua/37480/11 "2024-05-05T11:40:24Z")

</div>

just tested it, messages work if I put them before the function, not in

---

<div class="post-metadata">

**Author:** ![Stroogles](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@Stroogles](https://discourse.codecombat.com/u/Stroogles)\
**Post date:** [May 5, 2024, 11:43am UTC](https://discourse.codecombat.com/t/level-taunting-lua/37480/12 "2024-05-05T11:43:03Z")

</div>

like this?

```python
function dealEnemy(enemy)

    if enemy.type == "munchkin"

   then self:attack("munchkin")
    elseif enemy.type == "brawler"

     then self:say("come here!")
end
end

while true do
    local enemy = hero:findNearestEnemy()
    if enemy then
        dealEnemy(enemy)
    else
        hero:moveXY(30, 34)
    end
end

```

I just get a red X

 ![image](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/4/9/49d6811157dc1a238ea59592f3f909e71ed4f88c.jpeg)

---

<div class="post-metadata">

**Author:** ![MarmiteOnToast](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/marmiteontoast/32/46649_2.png) [@MarmiteOnToast](https://discourse.codecombat.com/u/MarmiteOnToast)\
**Post date:** [May 5, 2024, 11:49am UTC](https://discourse.codecombat.com/t/level-taunting-lua/37480/13 "2024-05-05T11:49:49Z")

</div>

> [@Stroogles](#):
>
> ` then self:attack("munchkin")`

I just tried the code again. I changed `"munchkin"` to `enemy` and it worked fine.

---

<div class="post-metadata">

**Author:** ![Stroogles](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@Stroogles](https://discourse.codecombat.com/u/Stroogles)\
**Post date:** [May 5, 2024, 12:03pm UTC](https://discourse.codecombat.com/t/level-taunting-lua/37480/14 "2024-05-05T12:03:07Z")

</div>

with the original code? or most recent one I gave?

---

<div class="post-metadata">

**Author:** ![MarmiteOnToast](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/marmiteontoast/32/46649_2.png) [@MarmiteOnToast](https://discourse.codecombat.com/u/MarmiteOnToast)\
**Post date:** [May 5, 2024, 12:05pm UTC](https://discourse.codecombat.com/t/level-taunting-lua/37480/15 "2024-05-05T12:05:19Z")

</div>

The most recent one

---

<div class="post-metadata">

**Author:** ![Stroogles](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@Stroogles](https://discourse.codecombat.com/u/Stroogles)\
**Post date:** [May 5, 2024, 12:06pm UTC](https://discourse.codecombat.com/t/level-taunting-lua/37480/16 "2024-05-05T12:06:53Z")

</div>

I’m still given the X with “that, arguments[2]”

---

<div class="post-metadata">

**Author:** ![Stroogles](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@Stroogles](https://discourse.codecombat.com/u/Stroogles)\
**Post date:** [May 5, 2024, 12:10pm UTC](https://discourse.codecombat.com/t/level-taunting-lua/37480/17 "2024-05-05T12:10:05Z")

</div>

```python
function dealEnemy(enemy)

    if enemy.type == "munchkin"

   then self:attack("munchkin")

    if enemy.type == "brawler"

     then self:say("come here!")

while true do
    local enemy = hero:findNearestEnemy()
    if enemy then
        dealEnemy(enemy)
    else
      self:say("no enemies nearby")
    end
end
    end
end
end

```

changed “move” to self:say(“no enemies nearby”), and no message is given

---

<div class="post-metadata">

**Author:** ![MarmiteOnToast](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/marmiteontoast/32/46649_2.png) [@MarmiteOnToast](https://discourse.codecombat.com/u/MarmiteOnToast)\
**Post date:** [May 5, 2024, 12:11pm UTC](https://discourse.codecombat.com/t/level-taunting-lua/37480/18 "2024-05-05T12:11:44Z")

</div>

Hm, it runs with no problems for me

I don’t think that code will run if the hero doesn’t attack, as there’ll always be enemies.

Do you have any other heroes you could use? I’ve seen a few other solutions where they just changed the hero and it was fine

---

<div class="post-metadata">

**Author:** ![Stroogles2](https://avatars.discourse-cdn.com/v4/letter/s/c2a13f/32.png) [@Stroogles2](https://discourse.codecombat.com/u/Stroogles2)\
**Post date:** [May 5, 2024, 12:19pm UTC](https://discourse.codecombat.com/t/level-taunting-lua/37480/19 "2024-05-05T12:19:49Z")

</div>

apparently there’s a limit on new users so I had to go run and make a new account, but I just tried using all of my available hero’s with no luck

---

<div class="post-metadata">

**Author:** ![MarmiteOnToast](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/marmiteontoast/32/46649_2.png) [@MarmiteOnToast](https://discourse.codecombat.com/u/MarmiteOnToast)\
**Post date:** [May 5, 2024, 12:39pm UTC](https://discourse.codecombat.com/t/level-taunting-lua/37480/20 "2024-05-05T12:39:16Z")

</div>

Oh 😕

I’m really sorry that I can’t help, I’ll look into it further and update you if I find anything.

[Next page](https://discourse.codecombat.com/t/level-taunting-lua/37480.md?page=2)
