Help with reward and ruination level


#1

I’m very new to this and I haw problem with this level

the artillery is not shooting the gem before enemy landed at the gem

while True:
    enemy = self.findNearestEnemy()
    if enemy:
        enemyPos = enemy.pos.x + " " + enemy.pos.y
        self.say("Enemy at " + enemyPos)
    item = self.findNearestItem()
    if item:
        itemPos = item.pos.x + " " + item.pos.y
        self.say("Item at " + itemPos) 
    
    
   

http://imgur.com/k8fcs42

thanks in advance


#2

Thanks for formatting your code properly!

I took a look and fixed this, sorry about that!


#3

I’m having the same issue now. I tried with my code, and then pasted in this exact code, and I’m still having the problem of getting the gem blown up. Any suggestions?


#4

Hi, I took a look at it and think I’ve got it fixed.

Please give it another try!


#5

Cool – I think that’s got it. Thanks!


#6

Hi,

What I do wrong?

http://my.jetscreenshot.com/25938/20160609-90gb-135kb.jpg


#7

findItems returns a list, not a single item.
You probably want item = hero.findNearest(hero.findItems()) to get the nearest item or None if none exists.


#8

UltCombo,

Its Works! Thanks!


#9

I’m getting a strange error suggesting I use “if pos:”

while True: 
#throws err: pos was null but this is the code that the level starts with
    enemy = hero.findNearestEnemy()
    if enemy:
        enemyPos = enemy.pos.x + " " + enemy.pos.y
        hero.say("Enemy at " + enemyPos)
        
    # Now that you have sweet revenge, why not have your cake and eat it, too?
    # Find the item's position and say it for your artillery to target.
    gem = hero.findNearestItem()
    if gem:
        #target the gem
        gemPos = gem.pox.x + " " + gem.pos.y
        hero.say ("Gem at " + gemPos)

The code I’m using is apparently identical to the code in the help and the suggested code. I don’t know if I’m the source of the error.
screengrab

thank you
Dennis


#10

Our “helpful” error message is actually throwing you off the trail.

The actual error at the bottom is: Line 5, time 0.0, TypeError: Cannot read property 'x' of undefined. This is telling you that you are trying to access the x property of a variable (or another property) that isn’t defined. Often because the variable hasn’t been defined, or a typo.

Take a look at that line again. I’m going to put a note down so we can improve this message in the future.


#11

Thank you for the quick response!