# I need help with village guard!

**URL:** https://discourse.codecombat.com/t/i-need-help-with-village-guard/4034
**Category:** Uncategorized
**Created:** [May 26, 2015, 2:34pm UTC](https://discourse.codecombat.com/t/i-need-help-with-village-guard/4034 "2015-05-26T14:34:57Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![bingoned](https://avatars.discourse-cdn.com/v4/letter/b/d78d45/32.png) [@bingoned](https://discourse.codecombat.com/u/bingoned)
#### Post date: [May 26, 2015, 2:34pm UTC](https://discourse.codecombat.com/t/i-need-help-with-village-guard/4034/1 "2015-05-26T14:34:57Z")

</div>

I’ve been stuck on this level for a week!

every time i kill the first two goblins, the third one comes from the left and kills one of my villagers!  
my hero can never get there quick enough, and I’ve tried everything…

I’ve reset the level so many times that i can’t post my code here cause i would have to go through all of that headache again!!

i was using lua, someone please help!!!

---

<div class="post-metadata">

### Author: ![Magicfloatincow](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/magicfloatincow/32/3855_2.png) [@Magicfloatincow](https://discourse.codecombat.com/u/Magicfloatincow)
#### Post date: [May 26, 2015, 2:37pm UTC](https://discourse.codecombat.com/t/i-need-help-with-village-guard/4034/2 "2015-05-26T14:37:39Z")

</div>

Hello bingoned I would like to see your code for any problems and if it can work.

---

<div class="post-metadata">

### Author: ![ChronistGilver](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/chronistgilver/32/3778_2.png) [@ChronistGilver](https://discourse.codecombat.com/u/ChronistGilver)
#### Post date: [May 26, 2015, 4:07pm UTC](https://discourse.codecombat.com/t/i-need-help-with-village-guard/4034/3 "2015-05-26T16:07:15Z")

</div>

You could just copy and paste your code here.

Are you moving back and forth between the two entrances? If you aren’t, then that might explain your problem.

---

<div class="post-metadata">

### Author: ![Vlevo](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/vlevo/32/2074_2.png) [@Vlevo](https://discourse.codecombat.com/u/Vlevo)
#### Post date: [May 26, 2015, 7:29pm UTC](https://discourse.codecombat.com/t/i-need-help-with-village-guard/4034/4 "2015-05-26T19:29:53Z")

</div>

(using Lua) If I run the default code then I get basically what you are describing, iow, I run back and forth a couple of times killing ogres, then one gets in far enough to kill a peasant before I can kill it.

But if I make the change to the code that the comments tell me to make it works perfectly.

```python
    -- Now move to the right entrance.
    -- Use "if" to attack if there is an enemy.

```

The intention of the code is:  
—You go left and check  
—You go right and check  
—repeat, until done.

All you have to do is either retype (or cough-copy&paste-cough) all the code for leftEnemy below the comments, change the move to the coords for the rightX and change those four "left"s to "right"s and BAM!! it works as intended…

---

<div class="post-metadata">

### Author: ![bingoned](https://avatars.discourse-cdn.com/v4/letter/b/d78d45/32.png) [@bingoned](https://discourse.codecombat.com/u/bingoned)
#### Post date: [May 27, 2015, 1:21pm UTC](https://discourse.codecombat.com/t/i-need-help-with-village-guard/4034/5 "2015-05-27T13:21:51Z")

</div>

heres my code, i don’t know what I’m doing wrong though!

---

<div class="post-metadata">

### Author: ![Kirito](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/kirito/32/2654_2.png) [@Kirito](https://discourse.codecombat.com/u/Kirito)
#### Post date: [May 27, 2015, 5:15pm UTC](https://discourse.codecombat.com/t/i-need-help-with-village-guard/4034/6 "2015-05-27T17:15:02Z")

</div>

I don’t know lua, but make the code check for an enemy. Then attack the enemy if it is there. Lastly you should make your character move to the spot where you started. Repeat.
