I am having a little trouble with my code it says that paladin has no method"canCast" but the paladins had the method in grim determination, so if someone could tell me what I am doing wrong, that would be great.
…
// Fight your way into the Inner Sanctum of the ogre chieftain, and defeat her.
function command(){
var friends = hero.findFriends();
var paladin = hero.findByType(“paladin”);
for(var i = 0; i < friends.length; i += 1){
var friend = friends[i];
var enemy = friend.findNearestEnemy();
if (friend && enemy) {
if (enemy.type == (“catapult”)) {
hero.command(friends[0], “attack”, catapult);
hero.command(friends[1], “attack”, catapult);
}else{
hero.command(friend, “attack”, enemy);
if (hero.health < 2500 && paladin.canCast(“heal”)) {
hero.command(paladin, “cast”, “heal”, hero);
}
}
}
}
}
function summon(){
if (hero.gold > hero.costOf(“soldier”)) {
hero.summon(“soldier”);
}
}
function fight(){
var enemy = hero.findNearestEnemy();
if (enemy) {
if (hero.canCast (“chain-lightning”)) {
hero.cast(“chain-lightning”, enemy);
hero.shield();
}else if(hero.isReady(“bash”)){
hero.bash(enemy);
hero.shield();
}else{
hero.attack(enemy);
hero.shield();
}
}
}
while(true) {
summon();
fight();
command();
}
…
Okay I loaded your code and I find several errors at first glance.
#1: catapult isn’t defined. u said "if enemy.type == “catapult” but u never defined what catapult is.
#2: paladin, you defined it as hero.findByType(“paladin”), which will return an array of all living paladins, not 1, which is why the canCast heal won’t work.
Also as a tip, unless your hero is within 3 meters of an enemy, use "hero.move(enemy.pos); ) so you can command your troops more and they won’t just stand there and do nothing.
Also, you have to use flags. Because in the end I see you standing in a corner summoning soldiers. Flags or Twilight Glasses are necessary.
well, I tried fixing it, but it showed me another error:
// Fight your way into the Inner Sanctum of the ogre chieftain, and defeat her.
// Fight your way into the Inner Sanctum of the ogre chieftain, and defeat her.
function disassembleCatapults(){
var catapults = hero.findByType("catapult");
var friends = hero.findFriends();
for(var i = 0; i < catapults.length; i += 1){
var catapult = catapults[i];
if (catapult) {
hero.command(friends[0], "attack", catapult[0]);
hero.command(friends[1], "attack", catapult[1]);
}else{
break;
}
}
}
function healHero(){
var paladins = hero.findByType("paladin");
for(var i = 0; i < paladins.length; i += 1){
var paladin = paladins[i];
if (hero.health < 2500 && paladin.canCast("heal", hero)) {
hero.command(paladin, "cast", "heal", hero);
}
}
}
function command(){
var friends = hero.findFriends();
var paladin = hero.findNearest("paladin");
for(var i = 0; i < friends.length; i += 1){
var friend = friends[i];
var catapult = hero.findByType("catapult");
var enemy = friend.findNearestEnemy();
if (friend && enemy) {
hero.command(friend, "attack", enemy);
}
}
}
function summon(){
if (hero.gold > hero.costOf("soldier")) {
hero.summon("soldier");
}
}
function fight(){
var enemy = hero.findNearestEnemy();
if (enemy) {
if (hero.canCast ("chain-lightning")) {
hero.cast("chain-lightning", enemy);
hero.shield();
}else if(hero.isReady("bash")){
hero.bash(enemy);
hero.shield();
}else{
hero.attack(enemy);
hero.shield();
}
}
}
while(true) {
summon();
fight();
command();
healHero();
disassembleCatapults();
}
I ran into problems here:
function disassembleCatapults(){
var catapults = hero.findByType("catapult");
var friends = hero.findFriends();
for(var i = 0; i < catapults.length; i += 1){
var catapult = catapults[i];
if (catapult) {
hero.command(friends[0], "attack", catapult[0]);
hero.command(friends[1], "attack", catapult[1]);
}else{
break;
}
}
}
I changed it and it stopped bugging, but my troops died and the tower finished me off.
// Fight your way into the Inner Sanctum of the ogre chieftain, and defeat her.
// Fight your way into the Inner Sanctum of the ogre chieftain, and defeat her.
function disassembleCatapults(){
var catapults = hero.findByType("catapult");
var friends = hero.findFriends();
for(var i = 0; i < catapults.length; i += 1){
var catapult = catapults[i];
if (catapult) {
hero.moveXY(catapult.pos.x, catapult.pos.y);
}else{
break;
}
}
}
function healHero(){
var paladins = hero.findByType("paladin");
for(var i = 0; i < paladins.length; i += 1){
var paladin = paladins[i];
if (hero.health < 2500 && paladin.canCast("heal", hero)) {
hero.command(paladin, "cast", "heal", hero);
}
}
}
function command(){
var friends = hero.findFriends();
var paladin = hero.findNearest("paladin");
for(var i = 0; i < friends.length; i += 1){
var friend = friends[i];
var catapult = hero.findByType("catapult");
var enemy = friend.findNearestEnemy();
if (friend && enemy) {
hero.command(friend, "attack", enemy);
}
}
}
function summon(){
if (hero.gold > hero.costOf("soldier")) {
hero.summon("soldier");
}
}
function fight(){
var enemy = hero.findNearestEnemy();
if (enemy) {
if (hero.canCast ("chain-lightning")) {
hero.cast("chain-lightning", enemy);
hero.shield();
}else if(hero.isReady("bash")){
hero.bash(enemy);
hero.shield();
}else{
hero.attack(enemy);
hero.shield();
}
}
}
while(true) {
summon();
fight();
command();
healHero();
disassembleCatapults();
}