Bookkeeper help, plz!


#1

This just doesn’t work.
On the statement:

 if nearest_item: 
        self.move({nearest_item, nearest_item})

it highlights the comma and the space after it and says: “Your parentheses must match; Unexpected Token.”

Here is my code…


defeated == 0
while True:
    enemies = self.findEnemies()
    nearest_enemy = self.findNearest(enemies)
    if enemies and nearest_enemy:
        self.attack(nearest_enemy)
        defeated=defeated+1
    if self.now() > 15:
        self.moveXY(59, 33)
        self.say("I killed" + defeated + "ogres")
        break

while True:
    items = self.findItems()
    nearest_item = self.findNearest(items)
    if nearest_item: 
        self.move({nearest_item, nearest_item})
    if self.now()>30:
        self.moveXY(58, 33)
        self.say(self.gold)
        defeated=0
        break      

while True:
    enemies = self.findEnemies()
    nearest_enemy = self.findNearest(enemies)
    if enemies and nearest:
        self.attack(nearest_enemy)
        defeated=defeated+1 
    if self.now() > 45:
        self.moveXY(59, 33)
        self.say("I killed" + defeated + "ogres")
        break

#2

The function self.move expects an object with an x and an y value.

All the objects that you detect have the member .pos that gives their position. Example:
self.pos, enemy.pos, item.pos, flag. pos

If you want to move to their location just do:

self.move(nearest_item.pos)

If you want to move to a specific point, lets say (20,30) using self.move, then call:

self.move({'x':20, 'y':30})

This is why you sought you need the construction { , }


#3

Hah, tried it, and then it was giving me NaN, then I worked around that by counting xD