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())
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.
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.