Timber Guard(python) moving problems

How do I move my troops without a target?

while True:
    # Collect gold.
    gold = hero.findNearestItem()
    # If you have enough gold, summon a soldier.
    if hero.gold > hero.costOf("soldier"):
        hero.summon("soldier")
    # Use a for-loop to command each soldier.
    # For loops have two parts: "for X in Y"
    # Y is the array to loop over.
    # The loop will run once for each item in Y, with X set to the current item.
    for friend in hero.findFriends():
        if friend.type == "soldier":
            enemy = friend.findNearestEnemy()
            # If there's an enemy, command her to attack.
            # Otherwise, move her to the right side of the map.
            if enemy:
                hero.command(friend, "attack", enemy)
                
            else:
                hero.command(friend, "move", )

You can specify a position in the move's target location. Use {'x': xValue, 'y': yValue}(Replace xValue and yValue with the number of your choice) in the move’s “target”.

3 Likes

That’s good, but the enemies get to the farthest people before my soldier get to the enemies.

You want to do this:

{'x':66,'y':50}

Yeah, missed the { }

How do i get my soldiers to the enemies it time?

In the else statement were there aren’t any enemies try to command them to move wherever you want them to go

Ok, that might work…

Alright, the problem was, the XY coordinates were: y was too high, and x was too far to the left.
I’m finally done with this level!

Good job @CocoCharlie

Thanks @Archipelago-Gold!!

1 Like

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