TypeError: Need an object - Frozen Fortress (Python)

Hello,

my code raises TypeError: Need an object on line number 47:
while (mana < (mana_needed + mana_buffer)):

All my code here:

# CodeCombat Level: "Frozen Fortress"

# Initiate variables
upgrade_round = 0
positions = ["a", "b", "c", "d", "e", "f", "g", "h"]
level = {"a": 0, "b": 0, "c": 0, "d": 0, "e": 0, "f": 0, "g": 0, "h": 0}
tower_price = 10
mana_buffer = 10
min_dist_to_enemy = 13

# Set algorithm attributes
priority = {"a": 1, "b": 1,
            "c": 1, "d": 1,
            "e": 1, "f": 1,
            "g": 1, "h": 1}

tower_types = {"a": "farm",
               "b": "farm",
               "c": "farm",
               "d": "farm",
               "e": "farm",
               "f": "farm",
               "g": "farm",
               "h": "barracks"}


# Define functions
def defense_enemies():
    enemy = hero.findNearestEnemy()
    
    if (enemy and enemy.distanceTo(hero) < min_dist_to_enemy):
        hero.ability("shockwave", enemy)


def tower_chnage_type(pos, tower_type, priority):
    hero.sell(pos)
    tower_types[pos] = tower_type
    priority[pos] = priority
    level[pos] = 0

# Main loop
while True:
    mana = hero.mana
    
    for pos in positions:
        mana_needed = level[pos] * tower_price * priority[pos]
        while (mana < (mana_needed + mana_buffer)):  # <-- Error indicated here
            defense_enemies()
            mana = hero.mana
        
        for _i in priority[pos]:
            hero.build(tower_types[pos], pos)
            level[pos] += 1
    
    defense_enemies()
    mana_buffer = 100 * upgrade_round
    upgrade_round += 1

What kind of error should I look for? Do I miss something?

Thanks for help

The problem is in this line for _i in priority[pos]: – you are trying to iterate a number.
I will report a bug with the wrong shown error. Thank you for the report.

1 Like

thank you!
range() fixed it :slight_smile:

Don’t you know why in the (fixed) loop

        for _i in range(priority[pos]):
            hero.build(tower_types[pos], pos)
            level[pos] += 1

for higher priority, let’s say 3, it doesn’t build up (upgrade) the tower +3 levels but only one?

What happens when I hero.build() but do not have enough mana for it? Does it wait until I earn mana, build/upgrade the tower and continue or skip the building line and continue?

Thank you for your hints.

Can u give me a code coffee script

Make your own code why do you need someone else to make code for you

Cause I am dum so pls give me a Python code pls

What the heck do you need it for

I want to beat a bully

Than learn coding we do not just give out code since that would not be learning

Ok thx for the advice

1 Like

We don’t give solutions and please be polite.

Another thing to think about is if I gave you a code you would not be the one beating the bullying I would

Ok thank you very much

How are you admin Bryukh

He is a level designer at coco so he is a admin

Im good. Please don’t mention me if you don’t need my attention

2 Likes