# Level and Method Help - Ogre Gorge Gouger

**URL:** <https://discourse.codecombat.com/t/level-and-method-help-ogre-gorge-gouger/13790>\
**Category:** Uncategorized\
**Created:** [February 6, 2018, 10:42am UTC](https://discourse.codecombat.com/t/level-and-method-help-ogre-gorge-gouger/13790 "2018-02-06T10:42:11Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christopher\_McMahon](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/christopher_mcmahon/32/7262_2.png) [@Christopher\_McMahon](https://discourse.codecombat.com/u/Christopher_McMahon)\
**Post date:** [February 6, 2018, 10:42am UTC](https://discourse.codecombat.com/t/level-and-method-help-ogre-gorge-gouger/13790/1 "2018-02-06T10:42:11Z")

</div>

```python
# Grab as much gold as you can, then retreat to your base and wall it off!
while hero.time < 20:
    # Collect coins
    hero.say("I should pick up a coin")
    while hero.gold < 60:
        nearest = hero.findNearest(hero.findItems())
        hero.move(nearest.pos)
    
while hero.pos.x > 16:
    # Retreat behind the fence
    hero.say("I should retreat")
    hero.move({'x' : 16, 'y' : 38})
# Build a fence to keep the ogres out.
hero.buildXY("fence", 21, 36)

```

I’m not really looking for general level help because I won’t get it unless I understand the concepts here.

This is one of the first levels using the `.move()` method. `.move()` takes an object literal (a dictionary is the vernacular I’m familiar with) and in the last few levels previous to this one, I’m wondering why code like this:

```python
while hero.pos.x < 40:
    hero.move({'x': 40, 'y': 35})

```

works fine but my OgreGorgeGouge script is not working. Essentially, it seems to me as though I have the same thing happening in both scripts.

My only guess would be the first statement `while hero.pos.x > 16:`(entered by default) can easily be a infinite loop. I know `.moveXY()` stops execution of your program until your hero gets to the positions passed in but I’m not sure I understand how my hero only takes a few steps when I am calling `.move()`.

I know object literals are quite important and I’ve been stumped for a bit on this levels so any and all help is appreciated. Please let me know if there is any other information I can provide.

---

<div class="post-metadata">

**Author:** ![TheDemonPrince](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/thedemonprince/32/7366_2.png) [@TheDemonPrince](https://discourse.codecombat.com/u/TheDemonPrince)\
**Post date:** [February 7, 2018, 12:08am UTC](https://discourse.codecombat.com/t/level-and-method-help-ogre-gorge-gouger/13790/2 "2018-02-07T00:08:52Z")

</div>

Take a screenshot of your equipment. Thx

---

<div class="post-metadata">

**Author:** ![Christopher\_McMahon](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/christopher_mcmahon/32/7262_2.png) [@Christopher\_McMahon](https://discourse.codecombat.com/u/Christopher_McMahon)\
**Post date:** [February 7, 2018, 1:41am UTC](https://discourse.codecombat.com/t/level-and-method-help-ogre-gorge-gouger/13790/3 "2018-02-07T01:41:59Z")

</div>

![gear](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/d/d91321d7e57a2606a12a917e371ba7a0af84bddd.png)

---

<div class="post-metadata">

**Author:** ![kyay10](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/kyay10/32/7337_2.png) [@kyay10](https://discourse.codecombat.com/u/kyay10)\
**Post date:** [February 14, 2018, 1:24am UTC](https://discourse.codecombat.com/t/level-and-method-help-ogre-gorge-gouger/13790/4 "2018-02-14T01:24:19Z")

</div>

remove the hero.say commands, they just make you slower, also you don’t need to loop until you have 60 coins, just loop while the time is less than 20

---

<div class="post-metadata">

**Author:** ![kyay10](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/kyay10/32/7337_2.png) [@kyay10](https://discourse.codecombat.com/u/kyay10)\
**Post date:** [February 14, 2018, 1:29am UTC](https://discourse.codecombat.com/t/level-and-method-help-ogre-gorge-gouger/13790/5 "2018-02-14T01:29:39Z")

</div>

> [@Christopher\_McMahon](#):
>
> the first statement while hero.pos.x \> 16:(entered by default) can easily be a infinite loop

actually, when you use the move command, the hero moves, so his x position changes, so it is impossible to be an infinite loop.

> [@Christopher\_McMahon](#):
>
> I’m not sure I understand how my hero only takes a few steps when I am calling .move().

your hero only takes one step to the target pos when you call the move command, you can think of it as the hero moving 1 unit in the direction of the position.

---

<div class="post-metadata">

**Author:** ![MunkeyShynes](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/munkeyshynes/32/9277_2.png) [@MunkeyShynes](https://discourse.codecombat.com/u/MunkeyShynes)\
**Post date:** [February 14, 2018, 1:56am UTC](https://discourse.codecombat.com/t/level-and-method-help-ogre-gorge-gouger/13790/6 "2018-02-14T01:56:49Z")

</div>

the main difference between moveXY and move methods is that when executing the moveXY method, the hero will not do anything else until this is completed. The code doesn’t move to the next line and no other line of code is considered until the hero is at the x,y coordinate of the position. With the move command, the hero takes a single step toward the target coordinates and then the code iterates through to see if there’s anything else it should, or could be doing. In some situations, one is better to use than the other. In other situations, it doesn’t make any significant difference.

---

<div class="post-metadata">

**Author:** ![kyay10](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/kyay10/32/7337_2.png) [@kyay10](https://discourse.codecombat.com/u/kyay10)\
**Post date:** [February 14, 2018, 2:02am UTC](https://discourse.codecombat.com/t/level-and-method-help-ogre-gorge-gouger/13790/7 "2018-02-14T02:02:52Z")

</div>

> [@MunkeyShynes](#):
>
> In some situations, one is better to use than the other

you can use move with a while loop that has nothing else than the move command and it will be the same as moveXY, so actually move is better than moveXY, but moveXY only cuts out some code

---

<div class="post-metadata">

**Author:** ![Christopher\_McMahon](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/christopher_mcmahon/32/7262_2.png) [@Christopher\_McMahon](https://discourse.codecombat.com/u/Christopher_McMahon)\
**Post date:** [February 14, 2018, 4:46pm UTC](https://discourse.codecombat.com/t/level-and-method-help-ogre-gorge-gouger/13790/8 "2018-02-14T16:46:50Z")

</div>

Thanks a lot guys! I think I’m starting to get the hang of it. Sometimes when I think I know how something works, its better to see how other people would explain it so all of this has put this into perspective for me.
