[Adventurer] Key Traps

The new desert level with pets: Key Traps.

This level finishes the series about pet.findNearestByType method.

Use your pet to find all keys, also the pet can help with potions.

2 Likes

Tried playing this level, not sure if this is a bug/me messing up.
I’m getting an error about “bronzeKey” where it’s not even mentioned:


here is the code :

# Get three keys and free the paladin.

def onSpawn(event):
    # The pet should find and fetch three keys.
    # You need next types: "bronze-key". "silver-key" and "gold-key".
    bronzeKey = pet.findNearestByType("bronze-key")
    if bronzeKey:
        pet.fetch(BronzeKey)
    silverKey = pet.findNearestByType("silver-key")
    if silverKey:
        pet.fetch(silverKey)
    goldKey = pet.findNearestByType("gold-key")
    if goldKey:
        pet.fetch(goldKey)

pet.on("spawn", onSpawn)

while True:
    enemy = hero.findNearestEnemy()
    if enemy and enemy.team == "ogres":
        hero.attack(enemy)
    if hero.health < 300:
        # You can use pets in the main thread too.
        potion = pet.findNearestByType("potion")
        if potion:
            hero.moveXY(potion.pos.x, potion.pos.y)

EDIT : Noticed typing error on my part. Fixed it and everything worked out.
Was a very fun level once I got it to work. Found it a bit weird how the doors automatically open without you walking near them though. Maybe add to the end of it and make it so that the hero then has to walk up to the doors?

1 Like

It’s a little hard to detect for user’s code when you have all three keys. I wanted to add that mechanic, but it made the sample code too complex for the early desert, so I simplified it.

1 Like

Minor bug
peasant can pick up key but it not counted

Thanks for level
Environment let me come up with really interesting solution

1 Like

Thanks. Did you use boss start for that? Which command?

1 Like
hero.command( hero.findByType( "peasant" )[ 0 ], "move", { x : 18, y : 60 } );
1 Like

Thanks. First I wanted to restrict boss stars. But I think it’s not “funny” enough :slight_smile: So I made peasants “lazy”.

2 Likes