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

[SOLVED] --delayed bomb--

I want to do in python and have this code:

while True:
    enemy = hero.findNearestEnemy()
    if enemy:
        distance = hero.distanceTo(enemy)
        if distance < 15:
            if hero.isReady("throw"):
                hero.throw(enemy)
        else:
            hero.attack(enemy)

now I have the problem, that my bomb is too late. How I can solve this? thanks in advance :smiley:

1 Like

Well, your code looks very solid…can you provide the link to the level?

1 Like

https://codecombat.com/play/level/shrapnel?

I took out the else command to show better the problem

But how do you defeat the enemies that are closer than 15 meters and the throw is not ready?

Andrei

with hero.attack(enemy)

But I think I have a time problem and in this lvl there should be a possibility to kill only with bombs because there are just some waves of enemy and not single ones

Well then put an else to that if that attacks the enemy.

Andrei

yeah that solves the lvl I know, but I was searching a way how I can kill without normal attacks. My idea is that if the enemy are close I can hit them in time, because when my hero figure out there is enemy and he shoot then its allready to late so my question is how i can shoot and hit with the bomb more precisely

1 Like

Can you buy the twilight glasses, because they allow you to see thourgh walls and then find the enemies that hide behind walls?

Andrei

I will check out, thanks if not maybe I have first to learn a bit more and do more lvls and do later. A friend programmer said maybe I should do with vector but this is something for more later I think

1 Like

You will also learn that, but in the Glacier (they are pretty complex unless you do the levels that explain them).

Andrei

Actually, after taking a closer look…I strongly recommend keeping the comments in place, as they tend to guide you and keep you on track:

            # Only throw if the ogres are more than 15m away.
            # Use "if" to compare distance to 15.
3 Likes

That is a really good advice for everyone! Thanks @dedreous for mentioning it!

Andrei

1 Like