Question about item.pos and "hear" in pet.on("hear", onHear)

what is item.pos and “hear” in python? What are their usages normally?

item.pos returns the vector (position coordinates) of that item. For example:

    item = hero.findNearestItem()
    if item:
        itemPos = item.pos.x + " " + item.pos.y
        hero.say(itemPos) # hero says something like "92 38"
        hero.say(item.pos) # hero says something like "{x: 92, y: 38, z: z: 0.50}"

The itemPos variable concatenates the x and y components of the vector. The first .say command returns the value of itemPos, which is more reader friendly. The second .say returns the full vector.

The pet.on(“hear”, onHear) statement tells the pet what to do when it hears something. The “hear” is the event, such as the hero giving it a verbal command. The onHear component calls the onHear function (definition), which contains the code for what the pet is supposed to do when it hears.

1 Like