Python - Create an Object?

Hi,

i´d like to know if i can create a object in python. Furthermore a Object with attributes like pos.x and pos.y.

I´m currently in the Level where you should go to an teleporter where an ogre comes to close to you. My idea was to use an array of objects and pass it on the “find.nearest(arr)” command to find the shortest way.

But i´m unable to do it and would like to know if its even possible or if i have to switch to “if self.pos.x < 40 and if self.pos.y < 40…”.

I hope that makes sense

1 Like
targetPositions = [{"x": 40, "y": 40}, {"x": 20, "y": 40}, {"x": 20, "y": 20}]
# or, using CodeCombat's Vector class
targetPositions = [Vector(40, 40), Vector(20, 40), Vector(20, 20)]
5 Likes

wow, works like a charm!

thank you very very much.

I have to say that this is one of the best tricks in CodeCombat I found so far! :smile: Thanks for sharing it!

Just to repeat it:

targetPositions = [ ... ]        # see above
target = self.findNearest(targetPositions)
self.move(target)
1 Like