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?
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.
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
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.