Can pet and hero run their code at the same time? (python)

If I have pet fetching potion, I stop attacking, etc. What gives? Thanks in advance

Are you using Python or JS?

1 Like

His title says python.

2 Likes

Lol, oops, I don’t really read titles

1 Like

you could define a function for the pet to run once it spawns in the background:

def func(event):
    while True:
        item = hero.findNearestItem()
        pet.fetch(item)
pet.on("spawn", func)
3 Likes

You could use

def onSpawn():
    #put whatever you want your pet to do
    pass
pet.on("spawn", onSpawn)
#Put your hero code down here

2 Likes

Yep, that’s what I would do, too!

1 Like

Use events. Define a function, like onSpawn() and then put code the pet will do. Then, use an event (pet.on()) to tell the pet what to do and it will run along side the main code. It’s to do with threads and such in programming, and using a pet.on event in CodeCombat creates a secondary thread that runs the pet’s code.

1 Like

Nice advice, but the guy who made this topic hasn’t posted since June 10 2022 which is about 11 months ago.