def letterIndex(word, letter):
# Step through each letter as an index of the word.
while chestIndex < len(ogreLetter):
# Store a character from the word with the current index.
letterIndex.append(shaman)
# If it is the required letter:
if ogreLetter:
# Then return the current index (number).
return chestIndex
# If nothing, return a default value
else:
return -1
ogreLetter = "z"
shaman = hero.findByType("thoktar")[0]
# Find the index and use it for finding the treasure.
chestIndex = letterIndex(shaman.id, ogreLetter)
hero.moveXY(16 + chestIndex * 8, 36)
Try to replace your function letterIndex(word, letter): with this:
def letterIndex (word, letter):
# Step through each letter as an index of the given word
for index in range ( 0, len (word), 1 ):
# Compare the letter in the word with the given letter
if (word [index] == letter):
# If it's required letter then return the current index
return index
# If nothing, return a default value
return 0