Hello!
I am having difficulty solving the stage “The One Wizard” in C++.
I am trying to make use of the code enemy.type == “ogre”;
Do I need to define enemy.type before I use it?
Error: Line 24: TypeError: Cannot read property “type” of null
Here’s my code
// Defeat as many ogres as you can.
// Use 'cast' and 'canCast' for spells.
int main() {
while(true) {
auto enemy = hero.findNearestEnemy();
if (enemy) {
if (hero.canCast("lightning-bolt")) {
hero.cast("lightning-bolt", enemy);
}
if (hero.canCast("chain-lightning")) {
hero.cast("chain-lightning", enemy);
}
else {
hero.attack(enemy);
}
}
else {
if (hero.canCast("regen")) {
hero.cast("regen", hero);
}
}
if (enemy.type == "ogre") {
hero.moveXY(6, 34);
}
}
return 0
}
Screenshot of the error and if somebody can explain what the error means I would be glad aswell! Just started out with coding and happy for all the information I can get