I think i got it, but it always says this.
is this a bug?
Have you bought new glasses before one of the last levels? The more advanced glasses don’t have the method self.findNearestItem()
anymore. Use self.findNearest(self.findItems())
instead.
Your code won’t work. Either rename Coin
to coin
in line 6 or call every other occurrence of coin
Coin
instead (would be necessary in line 7, 11, 15 and possibly some more).
A good way to prevent accidental variable-name-clutter is to use CamelCase.
# Examples:
# BAD Name: Hard to read, hard to write correct a second time
AlLeNeMiEs = self.findEnemies()
# BAD Name: should describe what is inside
friends = self.findEnemies()
# BAD Name: same as before on another level
var1 = self.findEnemies()
# BAD Name: all lowercase is hard to read (also to long)
munchkinsandthrowers = self.findEnemies()
# BAD Name: all uppercase isn't better
ENEMIES = self.findEnemies()
# ------------------------------
# Not so good Name: Conventions orders to start with a lowercase
Enemies = self.findEnemies()
### Explanation:
### While not harmful on it's own, Uppercase words are usually used
### for a completely different thing (e.g. classes in Java, constructs,
### structs). You don't have to deal with those things (yet), but it
### is better to learn it right from the beginning.
# ------------------------------
# GOOD Name: short and to the point
enemies = self.findEnemies()
# GOOD Name: CamelCase (notice how CamelCase looks like a Camel?)
coinPos = coin.pos
coinX = coin.pos.x
Let me try that. Thank you. I do have the kithgard worker glasses. I shall try that.
This isn’t working still. This is my code
totalGold = 0
loop:
Coin = self.findNearest(self.findItems())
CoinPos = coin.pos
x = CoinPos.x
y = CoinPos.y
self.moveXY(x, y)
totalGold += coin.value
totalGold += coin.value
if totalGold >= 25:
break
self.moveXY(58, 33)
self.say(“I am done collecting gold.”)
You didn’t do all of J_F_B_M’s suggestions. Do them, then come back.
I have done them. I understand that I am very dumb, but I still do not get it
Nobody said you’re dumb.
You did what I said before the horizontal ruler (changed findNearestItem
to findNearest(findItem())
. But your first Coin
is still uppercase while the other coin
s are all lowercase. For the computer the could be as well named Aldebar
and Zentaur
, they are completely different. To use a variable it has to be exactly the same every time you write it.
So decide: Use either Coin
or coin
, but not both. (I’d tend to coin
.)
I know. It is probably what you are thinking. But i have the level almost figured out.
The problem the others are getting at is you need to name variables and then call the variable exactly by name.
This means; coin does not equal Coin.
totalGold = 0
loop:
Coin = self.findNearest(self.findItems())
CoinPos = coin.pos #coin is not the variable name, you named it Coin
x = CoinPos.x
y = CoinPos.y
self.moveXY(x, y)
totalGold += coin.value #coin is not the variable name, you named it Coin
totalGold += coin.value #You are adding the coin's value twice
if totalGold >= 25:
break #You just broke out of the loop just to follow the rest of the code. Try placing the last two pieces inside this "if" statement, before the break (this is not required, however it is more readable)
self.moveXY(58, 33)
self.say("I am done collecting gold.")
Please do not post correct code. It takes the whole point out of the level by making it a simple matter of copying and pasting without learning.