# Help with level called keeping time

**URL:** <https://discourse.codecombat.com/t/help-with-level-called-keeping-time/3347>\
**Category:** Uncategorized\
**Created:** [April 2, 2015, 2:09pm UTC](https://discourse.codecombat.com/t/help-with-level-called-keeping-time/3347 "2015-04-02T14:09:21Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Harsh\_119](https://avatars.discourse-cdn.com/v4/letter/h/c6cbf5/32.png) [@Harsh\_119](https://discourse.codecombat.com/u/Harsh_119)\
**Post date:** [April 2, 2015, 2:09pm UTC](https://discourse.codecombat.com/t/help-with-level-called-keeping-time/3347/1 "2015-04-02T14:09:21Z")

</div>

This is my code so far

```python
loop:
     enemy = self.findNearestEnemy()
     if enemy and self.distanceTo(enemy) < 10:
         # Move to the left by subtracting 10 from your X coordinate.
         pass
         x = self.pos.x - 10
         y = self.pos.y 
         self.moveXY(x, y)
     else:
         # Move to the right by adding 10 to your X coordinate.
         pass
         x = self.pos.x + 10
         y = self.pos.y 
         self.moveXY(x, y)

```

One of the guy keeps on dying.  
 ![](https://sea2.discourse-cdn.com/flex016/uploads/codecombat/2257/64eda51754ad52c7.png)

---

<div class="post-metadata">

**Author:** ![FuzzicalLogic](https://avatars.discourse-cdn.com/v4/letter/f/73ab20/32.png) [@FuzzicalLogic](https://discourse.codecombat.com/u/FuzzicalLogic)\
**Post date:** [April 2, 2015, 2:41pm UTC](https://discourse.codecombat.com/t/help-with-level-called-keeping-time/3347/2 "2015-04-02T14:41:07Z")

</div>

First, when posting code, make sure you help us help you by formatting your code. You can do this by properly indenting and placing 3 tick marks (```) above and below your code.

Looking at your code, you aren’t exactly following the instructions:

1. For the first 10 secs ( `self.now() <= 10` ), you must fight. This means find an enemy and attack it.

2. After that, you must collect coins until 30 seconds has passed ( `self.now() <= 30`), Find the nearest item to move to each coin.

3. After that, you must fight again.

Until you learn to do this, your ally will continue to die.

---

<div class="post-metadata">

**Author:** ![J\_Butch](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/j_butch/32/3483_2.png) [@J\_Butch](https://discourse.codecombat.com/u/J_Butch)\
**Post date:** [December 11, 2015, 8:49pm UTC](https://discourse.codecombat.com/t/help-with-level-called-keeping-time/3347/3 "2015-12-11T20:49:56Z")

</div>

This is my code:

item = self.findNearestItem()  
enemy = self.findNearestEnemy()  
itemPos = item.pos  
x = itemPos.x  
y = itemPos.y  
loop:  
# If it’s the first 10 seconds, fight.  
if self.now() \< 10:  
self.attack(enemy)  
pass  
# Else, if it’s the first 30 seconds, collect coins.  
elif self.now() \< 30:  
self.moveXY(x, y)  
pass  
# After 30 seconds, join the raid!  
else:  
self.attack(enemy)  
pass

My guy fights ogres, but he doesn’t collect any money.

---

<div class="post-metadata">

**Author:** ![Hinkle](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/hinkle/32/3967_2.png) [@Hinkle](https://discourse.codecombat.com/u/Hinkle)\
**Post date:** [December 12, 2015, 7:34am UTC](https://discourse.codecombat.com/t/help-with-level-called-keeping-time/3347/4 "2015-12-12T07:34:21Z")

</div>

Look at the placement of your loop and when you find items and enemies. Currently you will fight 1 enemy and collect 1 coin.

---

<div class="post-metadata">

**Author:** ![DevinIV1](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/deviniv1/32/3105_2.png) [@DevinIV1](https://discourse.codecombat.com/u/DevinIV1)\
**Post date:** [December 12, 2015, 6:36pm UTC](https://discourse.codecombat.com/t/help-with-level-called-keeping-time/3347/5 "2015-12-12T18:36:09Z")

</div>

also, please format your code according to the FAQ

---

<div class="post-metadata">

**Author:** ![Shaumik\_Prabhu](https://avatars.discourse-cdn.com/v4/letter/s/ccd318/32.png) [@Shaumik\_Prabhu](https://discourse.codecombat.com/u/Shaumik_Prabhu)\
**Post date:** [April 1, 2016, 9:40pm UTC](https://discourse.codecombat.com/t/help-with-level-called-keeping-time/3347/6 "2016-04-01T21:40:35Z")

</div>

try to hire more troops.

---

<div class="post-metadata">

**Author:** ![Neel\_Sharma](https://avatars.discourse-cdn.com/v4/letter/n/e495f1/32.png) [@Neel\_Sharma](https://discourse.codecombat.com/u/Neel_Sharma)\
**Post date:** [April 2, 2016, 12:38am UTC](https://discourse.codecombat.com/t/help-with-level-called-keeping-time/3347/7 "2016-04-02T00:38:13Z")

</div>

True, that will work. But, please leave topics that are dead, dead.

---

<div class="post-metadata">

**Author:** ![Sivakumar\_Karthikraj](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/sivakumar_karthikraj/32/4071_2.png) [@Sivakumar\_Karthikraj](https://discourse.codecombat.com/u/Sivakumar_Karthikraj)\
**Post date:** [May 26, 2016, 4:26am UTC](https://discourse.codecombat.com/t/help-with-level-called-keeping-time/3347/8 "2016-05-26T04:26:43Z")

</div>

# Use your new skill to choose what to do: hero.now()

enemy = hero.findNearestEnemy()  
item = hero.findNearestItem()

while True:  
# If it’s the first 10 seconds, fight.  
if hero.now() \< 10:  
hero.attack(enemy)  
pass  
# Else, if it’s the first 30 seconds, collect coins.  
elif hero.now() \< 30:  
if item:  
pos = itemipos  
x = pos.x  
y = pos.y  
hero.moveXY(x, y)  
pass

```
# After 30 seconds, join the raid!
else:
    hero.attack(enemy)
    pass
```

---

<div class="post-metadata">

**Author:** ![Sivakumar\_Karthikraj](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/sivakumar_karthikraj/32/4071_2.png) [@Sivakumar\_Karthikraj](https://discourse.codecombat.com/u/Sivakumar_Karthikraj)\
**Post date:** [May 26, 2016, 9:35am UTC](https://discourse.codecombat.com/t/help-with-level-called-keeping-time/3347/9 "2016-05-26T09:35:19Z")

</div>

what is the problem with this code?

---

<div class="post-metadata">

**Author:** ![Opgamer76](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/opgamer76/32/8459_2.png) [@Opgamer76](https://discourse.codecombat.com/u/Opgamer76)\
**Post date:** [July 5, 2018, 6:58am UTC](https://discourse.codecombat.com/t/help-with-level-called-keeping-time/3347/10 "2018-07-05T06:58:00Z")

</div>

i don’t know so yeah dont ask me!

---

<div class="post-metadata">

**Author:** ![Chaboi\_3000](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/chaboi_3000/32/48486_2.png) [@Chaboi\_3000](https://discourse.codecombat.com/u/Chaboi_3000)\
**Post date:** [July 5, 2018, 7:37am UTC](https://discourse.codecombat.com/t/help-with-level-called-keeping-time/3347/11 "2018-07-05T07:37:34Z")

</div>

This topic is dead 2 years ago, so please don’t try reviving it.
