I keep trying to put in items[2] but it comes up witht this message even though I have defined items[2] to cordinates.
OwO use .pos
and remove the 6th line
And remember that list indexes start from 0
Still the same thing
Can you send your new code please?
while True:
items = hero.findItems()
gem = hero.findItems()
items = []
gem = []
items[1] = "gem[2]"
items.pos = "{x: 20, y: 35}"
# If the length of items is greater or equal to 2:
if len(items) >= 2:
hero.move(items[1])
# Else:
else:
hero.moveXY(40, 34)
# Move to the center mark.
Remove lines 3-10 and do hero.move(items[1].pos)
not hero.move(items[1])
still the same thing
Post your code please…
First, you are defining the items
to a blank list which result your hero don’t do anything. Second, you only need 1 array for items
, because gems are items
. Third, items
is an array, you cannot just move into an array’s positions.
Try this:
while True:
items = hero.findItems()
if len(items) >= 2: # When there are 2 or more gems...
item = items[1] # Remember the second thing for array is '1'
#Collect the Gem! Use moveXY()
else:
#Move to the center mark!
.
ITERATING AN ARRAY
An array is basically a list that stores things, where you need a “index” to iterate (also called loop) through it.
The number inside a square bracket is called a “index”, where it helps you iterate through an array, for example:
while True:
enemies = hero.findEnemies()
index = 0 # The index always start at 0
while index < len(enemies): # While the index is less than the array enemies
enemy = enemies[index] # Define the 'index' element enemies to 'enemy'
while enemy.health > 0: # The reason to do this is to keep focus on this target, if you do not check the health, the hero will attack every enemy in the array only ONCE
hero.attack(enemy)
index += 1 # Add index by 1, so you can kill the next enemy
# When there are no enemies, the while loop will finish and reset the index to 0 and find a new array of enemies if there are.
Your explanation is kind of incorrect, move only move 1 step, so he will only move once then go back to center again. Which will get him stuck
No, because it checks if there is an item, and if there ISN’T then it moves back
Still doesn’t work I think it might be a bug because I’ve tried everything and it keeps pulling up that message.
while True:
items = hero.findItems()
if len(items) >= 2: # When there are 2 or more gems...
item = items[1] # Remember the second thing for array is '1'
#hero.moveXY(item.pos.x, item.pos.y)
else:
#Move to the center mark!
Do moveXY(pos.x, pos.y) like in the sample code.
This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.