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

#1

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")

``````

#2

#3

@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?

#4

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

#5

`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?

#6

#7

@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` ?

#8

The values of coin should be stored in coins.

#9

And how do we get all the coin values?

#10

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

#11

@Gurrman

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?

#12

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

#13

@Gurrman yes!

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

#14

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

#15

@Gurrman great job so far!

This is where we have to understand how Python works.

example 1:

``````while True:
hero.say("One")
hero.say("Two")
hero.say("Three")
``````

is different from

example 2:

``````while True:
hero.say("One")
hero.say("Two")
hero.say("Three")
``````

First can you tell me what each example should do ?

#16

it has the hero say each number

#17

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

#18

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

#19

@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.

#20

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