Cannot Read Property 'Start' of Undefined(Hoarding Gold)


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
    if totalGold >= 25:
        # >= means totalGold is greater than or equal to 25.
        # This breaks out of the loop to run code at the bottom.

# Done collecting gold!
hero.moveXY(58, 33)
# Go to Naria and say how much gold you collected.
hero.say("I collected" + totalGold +" Gold")



@Gurrman revisit this line in your code:

for 'coin' in 'line-of-sight': 

Do you understand the difference between 'coin' and coin?

Where does 'line-of-sight' come from?


No I don’t understand the difference. Also Check line 2 In hero.findItems()


@Gurrman in your code currently:

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


Can you setup the for loop to iterate over the coins array?



@Gurrman sure that is correct.

You will get an error if you don’t define coins before iterating through it.

So what should be stored in coins ?


The values of coin should be stored in coins.


And how do we get all the coin values?


I don’t know how do you get all coin values?



So my character is wearing the Fine Wooden Glasses and gets the following code powers by wearing them:

Which function do you think will give me all of the coins in the game?


findItems() so should i use this code before calling for coin in coins:


@Gurrman yes!

look at your line of code coin = hero.findItems and correct it, now that you know what to do.


The coin function works but it won’t stop before 30 gold
How do I input this into for item in coins?


@Gurrman great job so far!

This is where we have to understand how Python works.


example 1:

while True:

is different from

example 2:

while True:

First can you tell me what each example should do ?


it has the hero say each number


Can you be a little more specific? What does it do exactly.


the hero says one then two then three but example 2 isn’t indented.


@Gurrman are you sure that is all that it does?

Do you have notepad? or a place where you can copy-paste all of your current code?

If you do try replacing your current code with the example and find out.


example 2 isn’t indented so it won’t work