I’ve looked through the other threads about coins but I can’t find an answer for python. How do you distinguish between coin types? I thought maybe it would be something like self.findItems(“gold coin”)
or self.findItems(“gold coin 5”) but I just can’t figure it out.
you use coin.value
I do not think the value 5 gems get identified in connection with findByType(“coin”), just FYI. I strongly recommend findItems() and then the .value property. One way to condense the loop coding is as follows:
hiValueCoins = [coin for coin in self.findItems() if coin.value > 2 ]
But depending on what you are doing next, you are probably better off doing the manual loop with additional calculations…
so why doesn’t something like this work?
if item and item.value > 2:
self.moveXY(item.pos.x, item.pos.y)
Give us an example where this does not work. Is there an error? If so, what is it? What happens when you use this code?
If you are populating item with a variation of the .findNearest() or .findNearestItem, that code will not move unless the item is gold+. So, a nearby copper results in no movement…
ok. so I’m on backwoods treasure specifically atm. This is the code I’m using.
loop:
item = self.findNearest(self.findItems())
enemy = self.findNearest(self.findEnemies())
flag = self.findFlag()
if flag:
self.pickUpFlag()
elif enemy:
if self.isReady("cleave"):
self.cleave(enemy)
elif self.isReady("bash"):
self.bash(enemy)
else:
self.attack(enemy)
elif item:
self.moveXY(item.pos.x, item.pos.y)
else:
self.moveXY(40, 32)
What do I have to change to pick up only gold coins? I’ve tried using .value
loop:
item = self.findNearest(self.findItems())
enemy = self.findNearest(self.findEnemies())
flag = self.findFlag()
if flag:
self.pickUpFlag()
elif enemy:
if self.isReady("cleave"):
self.cleave(enemy)
elif self.isReady("bash"):
self.bash(enemy)
else:
self.attack(enemy)
elif item and item.value > 2:
self.moveXY(item.pos.x, item.pos.y)
else:
self.moveXY(40, 32)
But that doesn’t do anything.
My accessories are the quartz sense stone and the mahogany glasses. Is there a more advanced item I need first to make these distinctions?
hint: your current code is only going to pick up any coins if the closest coin is gold.
i.e. if the closest coin is not gold, nothing is picked up at all.
self.findItems() returns an array of all coins within your vision range. If you want only gold+ coins, do not apply self.findNearest to that array. Instead, you need to execute some sort of loop through the array, testing value and how close it is. One very common approach is to select the next coin based on the highest value of item.value/self.distanceTo(item).
There are more sophisticated approaches possible utilizing vectors that are discussed elsewhere on this board (these approaches would tend to ignore/discount a solitary gold when the rest of the coins are in the other direction…).
Also, are you sure you want to go chasing enemies when you are out of their attack range and they are out of yours? Think about adding a distance condition to your “elif enemy:” statement to allow more coin gathering.
If you do not have them, look into acquiring boots with the .move method. self.moveXY gets you there, but no additional code executes while you are moving.
could you please show me where people talk about this? Like I said, I’ve only seen people talking about Javascript.
I really need to see examples. Is the game going to eventually show me what you are talking about? It’s been showing me how to use arrays against enemies but will it eventually show me how to use them with items and their value?
Have you played Mad Maxer yet? The code you should have written finds the farthest enemy. If so, it is easy to adapt that code to find the highest value coin.
You’ll find that the Enchanted Spectacles are quite useful for this