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

Two Flowers Help

I have no idea what is wrong with my code because the only error I get is “Dont know how to transform: Set” and it will not give me more information

Here is my code:

# If the peasant is damaged, the flowers will shrink!

def summonSoldiers():
    if hero.gold >= hero.costOf("soldier"):
        hero.summon("soldier")

# Define the function: commandSoldiers
def commandSoldiers():
    friend = hero.findFriends()
    enemy = hero.findNearestEnemy()
    soldiers = hero.findByType("soldier")
    peasant = hero.findByType("peasant")
    x = peasant.pos.x
    y = peasant.pos.y
    for soldier in soldiers:
        hero.command(soldier, "defend", {x, y})
 
# Define the function: pickUpNearestCoin
def pickUpNearestCoin():
    item = hero.findNearestItem()
    if item:
        hero.move(item.pos)

while True:
    summonSoldiers()
    commandSoldiers()
    pickUpNearestCoin()

1 Like

hero.findByType("peasant") returns an array, even if there’s only one peasant.
You can’t find the .pos.x of an array. You need to find the nearest peasant in the peasant array.
:lion: :lion: :lion:

1 Like

Welcome to CodeCombat forums @Twister_Charlie! I think @Deadpool198’s got it from this point on but Welcome.

P.S. Good job with formatting your code :wink:

Edit: Great profile pick! I see you and Deadpool stylein :laughing:

One extra note. if there is only one peasant to track you can add one bit of code at the end to change it from an array to an object.

peasant = hero.findByType("peasant")[0]

So whatever is the first in this array will be assigned to the variable.

1 Like