Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

[SOLVED] Pet cant fetch potion?

hello, in “chase them” the couger says “i cannot carry that” on potion… ? stage is simple, dont understand what could go wrong… also - cant change couger if it makes any difference
i tried simple

pet.fetch("potion");

and

javascript
        // Find and fetch a "potion":
        var item = pet.findNearestByType("potion");
        if (item.type==="potion") {
        pet.fetch("potion");


ty for help^^

Delete this if. Item will be a potion.

Instead of “potion” put item

1 Like

I tried it already it doesnt work :c

Can you show me your whole code?

1 Like

Read comments

// Find and fetch a "potion":
        var potion = pet.findNearestByType("potion");  # There are other items too
        if (item.type==="potion") { # Why did you put three equals?
        pet.fetch("potion"); # Put potion instead, if you use a string
# then why did you define potion (item)

Example

from turtle import *

screen = Screen() # You define it like this '==' means equal, '=' means assign
screen.setup(400, 400)
screen.bgcolor('dodge blue')
1 Like
// You always need to define, heres a piece of script I used when playing games
(function(){//info
    if(window.updateInfo) return;
 
 
    var info = {};
    var info_container = document.createElement("div");
    info_container.style.position = "fixed";
    info_container.style.color = "white";
    info_container.style["pointer-events"] = "none";
    document.body.appendChild(info_container);
 
    function toggle_info_container(e){
        if(e.key == "i"){
            info_container.style.display = info_container.style.display=="block" ? "none" : "block";
        }
    }
    window.addEventListener("keyup", toggle_info_container);
 

@Ksensei - as @AnSeDra says can you post all your code for the level? That way we can try running it and see where the problem is.

ive been trying different stuff since most basic didnt work (answering to why did i === for exeple)

javascript
function onSpawn(e) {
    while (true) {
        var enemy = pet.findNearestByType("munchkin");
        if (enemy && pet.isReady("chase")) {
            pet.chase(enemy);
        }
        // Find and fetch a "potion":
        var nearest = pet.findNearestByType("potion");
        pet.fetch("potion");
    }
}

Instead of “potion” put nearest. Does it work now?

1 Like

nope :frowning: tried it again just to make sure but no

Can you send us the whole code?

its what i posted above
it chases the ogres when its done with cooldown, but doesnt fetch saying “cant carry”

Do this, and check whether there’s a potion. What if there isn’t one? What will happen then?
Danny

when there was “nearest” instead of " “potion” " couger actually did go for the potions BUT it went for the second potion as well without waiting for cooldown of chase thus he braught both potions but 1 ogre stayed,
code works fully after i moved in the loop
code solution deleted

i understand the logic here of the loop, I just try to follow instructions in their order unless i dont make it work i improvise, i would have expected for “fetch(“potion”)” to work tho, potion is a constant the game recognizes, doesnt it?

“potion” is a string (text in quotes), a type of item. You want to target an object. A thing in the game, like a friend, and enemy or an item. The object’s name doesn’t represent it exactly.
Earlier you were able to attack a specific enemy e.g. hero.attack(“Kronk”), “potion” isn’t a specific thing, unlike “Kronk”.
Danny

2 Likes