The code I use says “Cannot Read Property ‘Start’ of Undefined”. What do I do?
# Collect 25 gold, and then tell Naria the total.
# Use break to stop collecting when totalGold >= 25.
totalGold = 0
while True:
coin = hero.findItems
for 'coin' in 'line-of-sight':
# Pick up the coin.
hero.moveXY(coin.pos.x, coin.pos.y)
# Add the coin's value to totalGold. (See the guide for more.)
# Get its value with: coin.value
totalGold += coin.value
pass
if totalGold >= 25:
# >= means totalGold is greater than or equal to 25.
# This breaks out of the loop to run code at the bottom.
break
# Done collecting gold!
hero.moveXY(58, 33)
# Go to Naria and say how much gold you collected.
hero.say("I collected" + totalGold +" Gold")
coin is a variable, or “container” that can store things 'coin' is a string or type of data
When we are setting up a for loop with the syntax in, we want to use a variable to store the current value.
'line-of-sight' is also a string, so unless you want to inspect each character in the string: l, i ,n, e, -, o, f, -, s, i, g, h, and t I wouldn’t use the string 'line-of-sight' for something to iterate over.
Looking back at the line as you mentioned: coin = hero.findItems The first issue is that you are referencing a function as if it was a variable. hero.findItems says give me the value of the contents stored in findItems. If instead we write hero.findItems() we are asking to execute the code stored in the findItems() function. Which is what we want to do. We want to run the function.
Also once we call hero.findItems(), remember that it returns an array. That array is then being stored in the variable coin and coin actually represents many coins! coin is our array. This doesn’t make sense as a coin should not be many coins. Try renaming the variable name (storage) from coin to coins
Now,
Can you setup the for loop to iterate over the coins array?