Keeping Time: Collecting coins


#1

I am currently stuck on the level, keeping time. Here is my code

loop:
nearest = self.findNearest(self.findEnemies())
# If it’s the first 10 seconds, fight.
if self.now() < 10:
self.attack(nearest)
pass
# Else, if it’s the first 30 seconds, collect coins.
elif self.now() < 30:
item = self.findItems()
self.moveXY(item.pos.x , item.pos.y)
pass
# After 30 seconds, join the raid!
else:
self.attack(nearest)
pass

On the collecting coin part, I keep getting a debug message that says,"pos was null. use a null check before accessing properties. Can somebody please help?


#2

You need to use an if statement


#3

Hello, Clambosham, and please read the FAQ on instructions how to format your code.
Surround your code vertically, above and below in triple backticks (the thing above tab)
Use if item: First, to clarify that there actually IS an item before checking the item.pos
Also, why don’t you use self.findNearest(self.findItems)) instead of self.findItems(),
as self.findItems() just finds listed items from the array, which can be further away.


#4

Thank you for the help.


#5

no problem! :slight_smile: