# Codecombat - Any advice for dangerous key

**URL:** <https://discourse.codecombat.com/t/codecombat-any-advice-for-dangerous-key/36507>\
**Category:** Level Help\
**Created:** [December 11, 2023, 3:11am UTC](https://discourse.codecombat.com/t/codecombat-any-advice-for-dangerous-key/36507 "2023-12-11T03:11:34Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ValentyP](https://avatars.discourse-cdn.com/v4/letter/v/3d9bf3/32.png) [@ValentyP](https://discourse.codecombat.com/u/ValentyP)\
**Post date:** [December 11, 2023, 3:11am UTC](https://discourse.codecombat.com/t/codecombat-any-advice-for-dangerous-key/36507/1 "2023-12-11T03:11:34Z")

</div>

The code runs but the dog just sits there.

 ![Screenshot 2023-12-10 at 7.09.01 PM](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/b/4/b44b74d958b48d81300da60db837b72a37771c30.jpeg)

---

<div class="post-metadata">

**Author:** ![Watamelon](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/watamelon/32/43741_2.png) [@Watamelon](https://discourse.codecombat.com/u/Watamelon)\
**Post date:** [December 11, 2023, 3:14am UTC](https://discourse.codecombat.com/t/codecombat-any-advice-for-dangerous-key/36507/2 "2023-12-11T03:14:51Z")

</div>

The event message is `"gold"`

---

<div class="post-metadata">

**Author:** ![ValentyP](https://avatars.discourse-cdn.com/v4/letter/v/3d9bf3/32.png) [@ValentyP](https://discourse.codecombat.com/u/ValentyP)\
**Post date:** [December 11, 2023, 3:31am UTC](https://discourse.codecombat.com/t/codecombat-any-advice-for-dangerous-key/36507/3 "2023-12-11T03:31:24Z")

</div>

cool thank you ///////////////////

---

<div class="post-metadata">

**Author:** ![NalfarCryptor](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/nalfarcryptor/32/37572_2.png) [@NalfarCryptor](https://discourse.codecombat.com/u/NalfarCryptor)\
**Post date:** [December 11, 2023, 3:38am UTC](https://discourse.codecombat.com/t/codecombat-any-advice-for-dangerous-key/36507/4 "2023-12-11T03:38:16Z")

</div>

huh there are still errors

---

<div class="post-metadata">

**Author:** ![NalfarCryptor](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/nalfarcryptor/32/37572_2.png) [@NalfarCryptor](https://discourse.codecombat.com/u/NalfarCryptor)\
**Post date:** [December 11, 2023, 3:40am UTC](https://discourse.codecombat.com/t/codecombat-any-advice-for-dangerous-key/36507/5 "2023-12-11T03:40:34Z")

</div>

> [@ValentyP](#):
>
> The code runs but the dog just sits there.
> 
> ![Screenshot 2023-12-10 at 7.09.01 PM](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/b/4/b44b74d958b48d81300da60db837b72a37771c30.jpeg)

on lines 5-8

```python
pet.findNearestByType("blahblahblah")

```

it should just be

```python
pet.findByType("blahblahblah")
```

---

<div class="post-metadata">

**Author:** ![ChickenMaster](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/chickenmaster/32/35104_2.png) [@ChickenMaster](https://discourse.codecombat.com/u/ChickenMaster)\
**Post date:** [December 11, 2023, 5:08pm UTC](https://discourse.codecombat.com/t/codecombat-any-advice-for-dangerous-key/36507/6 "2023-12-11T17:08:23Z")

</div>

Hey, try this code:

```python
# https://codecombat.com/play/level/dangerous-key
# Listen to the paladin and fetch the right key.

def onHear(event):
    # The pet can find the paladin and keys.
    paladin = pet.findNearestByType("paladin")
    goldKey = pet.findNearestByType("gold-key")
    silverKey = pet.findNearestByType("silver-key")
    bronzeKey = pet.findNearestByType("bronze-key")
    # If event.speaker is the paladin:
    if event.speaker == paladin:
        # If event.message is "Gold":
        if event.message == "Gold":
            # The pet should fetch the gold key.
            pet.fetch(goldKey)
        # If event.message is "Silver":
        if event.message == "Silver":
            # The pet should fetch the silver key.
            pet.fetch(silverKey)
        # If event.message is "Bronze":
        if event.message == "Bronze":
            # The pet should fetch the bronze key.
            pet.fetch(bronzeKey)

pet.on("hear", onHear)

```

P.S. if this is helpful, mark as solution.

---

<div class="post-metadata">

**Author:** ![JustALuke](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/justaluke/32/43608_2.png) [@JustALuke](https://discourse.codecombat.com/u/JustALuke)\
**Post date:** [December 11, 2023, 6:59pm UTC](https://discourse.codecombat.com/t/codecombat-any-advice-for-dangerous-key/36507/7 "2023-12-11T18:59:11Z")

</div>

Please don’t just post solutions (escpecially from github); he isn’t even using python.

---

<div class="post-metadata">

**Author:** ![ChickenMaster](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/chickenmaster/32/35104_2.png) [@ChickenMaster](https://discourse.codecombat.com/u/ChickenMaster)\
**Post date:** [December 11, 2023, 9:10pm UTC](https://discourse.codecombat.com/t/codecombat-any-advice-for-dangerous-key/36507/8 "2023-12-11T21:10:50Z")

</div>

This is not from github…

---

<div class="post-metadata">

**Author:** ![JustALuke](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/justaluke/32/43608_2.png) [@JustALuke](https://discourse.codecombat.com/u/JustALuke)\
**Post date:** [December 12, 2023, 1:56pm UTC](https://discourse.codecombat.com/t/codecombat-any-advice-for-dangerous-key/36507/9 "2023-12-12T13:56:20Z")

</div>

> <https://github.com/vadim-job-hg/CodeCombat/blob/master/Desert/DangerousKey/DangerousKey.py>
