Here are some reason why a level might now be getting a success or complete as expected. All code examples shown are from CodeCombat, but the types of errors can be seen across CodeCombat and Ozaria alike.

What's wrong with my code?

There are a lot of possible answers to this question, and sometimes the question can be difficult to answer, but there are also a lot of common errors shared by programmers. These are the things I look for first.

Simple spelling errors
It happens. Your student creates a variable named enemy but when they try to use it they type emeny and it takes four, five, six readings before you finally spot it.
Similarly, they type hero,attack(enemy) instead of hero.attack(enemy) -- hard to see the difference, but the comma in hero,attack(enemy) isn't going to do your students any good.
And capitals count too. hero.moveUp() works but hero.moveup does not!

Not following instructions for the level

There are levels that require you to defeat enemy units and there are levels that require you to build things.
For the fighting levels, we equip the heroes with a sword.
For building levels, we equip the heroes with a hammer.

The equipment the hero has determines which commands students can use. This means hero.attack() doesn't work on levels where the heroes have a hammer and hero.buildXY() doesn't work on levels where the heroes have a weapon.

Our instructions for that level will reflect that.  For example, Kithgard Gates, our first building level (and the last level in our introductory course) has the following instructions:

// Build 3 fences to keep the ogres at bay!

Order of Execution

Code runs in order. You have to set up the variable before you can use the variable.  For example:

myTarget1 = hero.findNearestEnemy()
myTarget2 = hero.findNearestEnemy()

The first two attacks both work because the myTarget1 variable was declared before it was used.  The last two attacks do not work because the myTarget2 variable has not been declared when they try to run.

Not checking to see if variables are storing any value

At first, we have the game set up so student won't encounter this problem, but later we introduce ambiguity. What happens if you try to attack an enemy but there are no enemies?

myTarget1 = hero.findNearestEnemy()

The first line stores the value of the expression on the right, which can be a command or a simple value, or even nothing, in the variable on the left.

So, when that line of code runs, if there is an enemy nearby, the value of that enemy is stored in that variable, and then when the program runs the next line of code and the hero will attack the enemy that is stored in the variable.

But what if there was no enemy to find when hero.findNearestEnemy() ran? Then myTarget1 will be empty and when the next line runs, the hero will just freeze up.

This is because the hero was told to attack the nothing stored in the variable. The hero is now experiencing an existential crisis and will just stand there.

But we can keep the hero safe from this peril, by checking to see if there is a value in the myTarget1 variable. 

myTarget1 = hero.findNearestEnemy()
if myTarget1:

On earlier levels, this is not needed, as we've set them up so that there will always be an enemy available, but when your students come across the more complicated levels, they'll need to check.

The same thing may happen when trying to use heroes special abilities, like cleave. Cleave is an attack that hits all enemies within 5 yards, but it takes 10 seconds before your hero can do it again. However, you can try to cleave more often. Again, this will just confuse the poor hero and they will stand there for a short period of time while trying to cleave.  To avoid this, you first check if cleave is ready using the isReady() command.

if hero.isReady("cleave"):

But what if there's no enemy?

if enemy:
    if hero.isReady("cleave"):

Did this answer your question?