[SOLVED] Pet won't fetch

I’m going for a high score on the Kithgard Brawl stage, and I’m attempting to use my good boi, the pet wolf, to fetch me those health potions while I hold the center field and shoot everything. However, my wolf will not fetch the potions at all. I’ve gotten my pets to fetch items before, so why isn’t he doing his job? Code below:

function potionFetch(){
    var needsHealing = hero.maxHealth / 2;
    if(hero.health < needsHealing){
        var item = hero.findByType("potion");
        if(item){
            pet.fetch(item);
        }
    }
}

pet.on("spawn", potionFetch);

hero.findByType returns a list, not a single item try:
hero.findNearest( hero.findByType("potion") )

I changed to what you suggested, but my wolf just runs in a circle around me, then runs up into me, as if he’s stuck, despite the potion being far off to the right.

Welcome welcome @DragonAce to the forum! It is a lovely place where you can share all kinds of stuff (appropriate of course), share bugs, and even get assistance for code! We suggest that you review this topic which shows all essentials of this board! And we suggest you review this topic which shows how to post your code correctly! Thanks!! :partying_face: :partying_face:

Maybe try changing potionFetch to onSpawn?
Lydia

Thanks for the welcome! I’m a bit dense at times so I’m sure I’ll be swinging by here often. I’ve already looked at how to post code correctly (not that specific document, but hopefully I got it close enough) and I’ll be sure to read the other one.

As for changing the function name, it didn’t do anything. He ran a lap around my character then pushed up into her.

1 Like

the potion isn’t there when the pet spawns, maybe try a “while true” loop to make the pet always try to get a potion, because at the beginning the requirements in the " if " aren’t fulfilled.

1 Like

That did the trick! My good boi is now doing his job! Thanks a lot!

2 Likes

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.