my mistake add
under coin = coins[coinIndex]
my mistake add
under coin = coins[coinIndex]
Oh so like this?
while coinIndex < len(coins):
coin = coins[coinIndex]
coinIndex += 1
distance = hero.distanceTo(coin)
yea.
thats it
20 charactersssss
It made it a bit better but now my character is walking collecting 4 coins and dying
Can you post your code?
This is my New code
while True:
coins = hero.findItems()
coinIndex = 0
nearest = None
nearestDistance = 9999
# Loop through all the coins to find the nearest one.
while coinIndex < len(coins):
coin = coins[coinIndex]
coinIndex += 1
distance = hero.distanceTo(coin)
# If this coin's distance is less than the nearestDistance
if distance < nearestDistance:
# Set nearest to coin
nearest = coin
# Set nearestDistance to distance
nearestDistance = distance
# If there's a nearest coin, move to its position. You'll need moveXY so you don't cut corners and hit a trap.
if coin:
hero.moveXY(nearest.pos.x , nearest.pos.x)
delete one indent
20 characters
found the mistake get rid of if coin:
and move hero.moveXY(nearest.pos.x , nearest.pos.x)
outside the while-loop
.
where outside the loop?
this loop. It is called a while-loop
like this?
while True:
coins = hero.findItems()
coinIndex = 0
nearest = None
nearestDistance = 9999
# Loop through all the coins to find the nearest one.
while coinIndex < len(coins):
coin = coins[coinIndex]
coinIndex += 1
distance = hero.distanceTo(coin)
# If this coin's distance is less than the nearestDistance
if distance < nearestDistance:
# Set nearest to coin
nearest = coin
# Set nearestDistance to distance
nearestDistance = distance
# If there's a nearest coin, move to its position. You'll need moveXY so you don't cut corners and hit a trap.
hero.moveXY(nearest.pos.x , nearest.pos.x)
I tried this and it didnāt work its still just collecting a few coins and killing themselves
no, move it outside this loop. Donāt move it outside of the while-true-loop
indent this by one
20 chars
It didnāt change anything
like this?
while True:
coins = hero.findItems()
coinIndex = 0
nearest = None
nearestDistance = 9999
# Loop through all the coins to find the nearest one.
while coinIndex < len(coins):
coin = coins[coinIndex]
coinIndex += 1
distance = hero.distanceTo(coin)
# If this coin's distance is less than the nearestDistance
if distance < nearestDistance:
# Set nearest to coin
nearest = coin
# Set nearestDistance to distance
nearestDistance = distance
# If there's a nearest coin, move to its position. You'll need moveXY so you don't cut corners and hit a trap.
hero.moveXY(nearest.pos.x , nearest.pos.x)
If there is a nearest, then move to it.
No need. I didnāt do it and it worked.
I tried this but all it did was make my character move stop move stop at the same places it was earlier still killing them
What is your current code and what is your equipment?
Programicon 3
boots of leaping
mahogany glasses
quartz sense stone
(misc armors and such)
and my code right now is
while True:
coins = hero.findItems()
coinIndex = 0
nearest = None
nearestDistance = 9999
# Loop through all the coins to find the nearest one.
while coinIndex < len(coins):
coin = coins[coinIndex]
coinIndex += 1
distance = hero.distanceTo(coin)
# If this coin's distance is less than the nearestDistance
if distance < nearestDistance:
# Set nearest to coin
nearest = coin
# Set nearestDistance to distance
nearestDistance = distance
# If there's a nearest coin, move to its position. You'll need moveXY so you don't cut corners and hit a trap.
if nearest:
hero.moveXY(nearest.pos.x , nearest.pos.x)