Help on the hunt begins


#1

I feel as if my code should not have any problems, but an error keeps popping up saying “burls” is not defined. Here is my code:


# Senick is trying to find the elusive Burleous Majoris!
# But he doesn't know how big a Burleous Majoris would be...
# Find the average size of this burl population to use as a baseline!

# This function returns average size of all the burls in an array.
def averageSize(burls):
    sum = sumSize(burls)
    # Remember the average is the sum of the parts divided by the amount!
    return sum / burls.length

# This function should return the sum of all the burls sizes.
def sumSize(burls):
    # Implement the sum function using the burls 'size'
    sum = 0
    for burl in burls:
        sum = sum + burl.size

while True:
    # Find the average size of the burls by calling the 'averageSize' function.
    averageSize()
    # Say the average size of the seen burls!
    hero.say(averageSize())

#2

After while true, try actually defining burls with findByType


#3

I tried that but it didn’t work.


#4

I’m not where you are yet but have you tried defining burls in a variable? and made sure that variable is able to be accessed by all blocks of code?


#5

What do you mean???


#6

he means to write burls equals findByType(“burls”)


#7

The array “burls” is already defined by the function itself. I don’t know why it isn’t working


#8

That is not true
(20 chars)


#9

you don’t define “burls” by putting it in a function. the parenthesis are meant for variables, so you can use the same function for different things, like this:

def heroAttack(unit):
    if unit:
        hero.attack(unit)

While True:
    enemy = hero.findNearestEnemy()
    heroAttack(enemy)
    door = hero.findNearest(hero.findByType("door"))#actual doors in the game are enemies, but let's just pretend they're neutral
    heroAttack(door)

If you want to use the function like that, then you will still have to define “burls”. Since you don’t need the function for anything but burls, you should probably just leave the parenthesis blank.


#10

The burl is type “burl”. Also, the hero has to say hero.say(averageSize(burls))


#11

once you do what @Seojin_Roy_Lee said, define burls using hero.findByType(“burls”). Along with the say statement, you have to do that every time you use the averageSize function like on the line before.


#12

It doesn’t work like that, what you see in the function is an argument.
an argument is not an object.

if you do not specify the argument when you call the function the argument will not be burls it will be: null.

def averageSize(burls):
sum = sumSize(burls)
return sum / burls.length

is the same thing has:

def averageSize(something):
sum = sumSize(something)
return sum / something.length