The Trials code problem


#1

I get a success but that is not my problem my problem is that if I comment this out: this.say(oasisGuardianDefeated);
Its at the bottom of the code. The code stops working, the champ just stands still and does nothing after defeating the first guardian. I have no idea why, I dont know if its my code or a bug.

This is my code:

// This level is intended to be for advanced players. The solution should be pretty complex with a lot of moving parts. It might also be a bit of a gear check unless you use "creative" methods.
// You need to make your way to the first trial (Oasis of Marr) killing enemies along the way. When you reach it, pick all the mushrooms to trigger the trial to begin. If you survive the onslaught, make your way to the next Oasis for the second trial, then the Temple. When all trials are complete you will have to face the final boss. Good luck!
// HINT: Glasses with a high visual range help tremendously on this level so buy the best you can get

self = this;

function oasisBossCheck ()
{
    if (enemy.type == 'ogre') 
    {        
        if (enemy.health <= 0) 
        {
        oasisGuardianDefeated++;
        }
    }
}
    
function oracleOfThaCheck ()
{
    if (enemy) 
    {
        
        if (enemy == 'Oracle-of-Zha') 
        {        
            if (enemy.health <= 0) 
            {
            oracleOfThaDefeated++;
            this.say("oracleOfThaDefeated");
            }
        }
    }
}

    var oasisGuardianDefeated = 0;
    var oracleOfThaDefeated = 0;
    
loop
{
    var enemiesAry = this.findEnemies();
    var enemiesAryPos = 0;
    var moreThan5Enemies = 0;
    
    enemy = this.findNearest(this.findEnemies());
    
    /* enable for cleave
    for(i = 0; i <= enemiesAry.length; i++)
    {
        if (enemy) {
        var distanceToEnemy = this.distanceTo(enemy);
        if (distanceToEnemy < 3) 
        {
            moreThan5Enemies++;
        }
        }
    } */
    
    // attack all enemys that are close
    for(i = 0; i <= enemiesAry.length; i++)
    {
        if (enemy) 
        {
           if (enemy.health === 550) {
               this.say(enemy.id);
           } 
            distanceToEnemy = this.distanceTo(enemy);
            if (distanceToEnemy < 20) 
            {
            /*    if (moreThan5Enemies >= 2 && this.isReady("cleave")) {
                    this.cleave(enemy);
                cleave//moreThan5Enemies = 0;
                } */
                while (enemy.health > 0) {
                   this.attack(enemy);  
                }
                
                oasisBossCheck ();
   
                if (enemy.health === 0) {
                   delete enemiesAry[enemiesAryPos];
                   //cleave// moreThan5Enemies = 0;
                }
                enemiesAryPos++;
            } else 
              {
                enemiesAryPos++;
              }
             
        }
        enemy = enemiesAry[enemiesAryPos];
    }
    // attack one enemy far away once
    if (distanceToEnemy > 20) 
    {
     enemy = this.findNearest(this.findEnemies());
        if (enemy) {
                 this.attack(enemy);
                 oasisBossCheck ();
        }
    }
    
    if (enemiesAryPos === 0) {
        item = this.findNearest(this.findItems());
        if (item) 
        {
            this.moveXY(item.pos.x, item.pos.y);
        }
    }

    //All enemies defeated, all items picked up, boss defeated move to next part  
    if (this.findEnemies().length === 0 && this.findItems().length === 0 && oasisGuardianDefeated === 1) 
    {
        this.moveXY(10, 45);
        this.moveXY(8, 98);
        this.moveXY(13, 95);
        oasisGuardianDefeated++;
    }
    //All enemies defeated, all items picked up, boss defeated move to next part  
    if (this.findEnemies().length === 0 && this.findItems().length === 0 && oasisGuardianDefeated === 3) 
    {
        this.moveXY(134, 129);
        oasisGuardianDefeated++;
    }
    //All enemies defeated, all items picked up, boss defeated move to next part  
    if (this.findEnemies().length === 0 && this.findItems().length === 0 && oasisGuardianDefeated === 5) 
    {
        this.moveXY(60, 120);
        this.moveXY(41, 96);
        this.moveXY(95, 91);
        oasisGuardianDefeated++;
    }
    
    
    if (this.findEnemies().length === 0 && this.findItems().length === 0 && oasisGuardianDefeated === 6) 
    {
        oracleOfThaCheck();
    }
    
        if (this.findEnemies().length === 0 && this.findItems().length === 0 && oracleOfThaDefeated === 1) 
    {
        this.say("I AM VICTORIOUS!!!");
        break;
    }
            this.say(oasisGuardianDefeated);


}

#2

Well i’m not sure about your specific question. but enemy.type is not “ogre” on the oasis guardian. its “oasis-guardian” also i dont think enemy == “Oracle-of-Zha” should work at all.


#3

Well I used your workaround with enemy.health to get the oasis guardians enemy.type and what I got was ogre and it works fine. My code just dosn’t work if I don’t say my counter variable oasisGuardianDefeated. That is very very strange, just copy and paste the code and see for yourself. The ID the OoZ I got is ‘Oracle of Zha’ but it didn’t work when I used it, so I added the - to it and it still won’t work. It’s type is shaman but since its a boss it should be accessible with id. The enemy IDs and types really need to get changed either you add an extra button to show the ID/type or something else where the ID/type can be seen or the names need to be the exact ID + type. The way it is now it’s not really useable.

-Ok so it dosnt matter what I say but if I dont use say it becomes an infinite loop…
-Also tried to use enemy.health === 550 && enemy.type==“shaman” this didnt work either, my guess is that the code is ignored because the level ends when oracle oZ is killed.


#4

Thank you for the report on the type of oasis-guardian. It’s properly configured to have the type of “oasis-guardian” but indeed it is showing a type in game of “ogre” as you reported. It would seem this is a bug in the thang templates. I will discuss it with nick and see if there’s something we can do to remedy it.

You aren’t meant to be able to access ID as far as I know. Have you tried this to check for the name of a unit? It works for me in JS.

if (String(enemy) == "Oracle of Zha") {

just as another FYI. you can beat the level just fine without ever using “types”. I do. So the level is very usable. :slight_smile: Nobody up until this thread has even noticed that the type is ogre. or if they have they have debugged it themselves found it and just used it. But more likely they didn’t even need the type. Nevertheless it’s a bug i want fixed! i want it to have the intended type!


#5

I would guess (but don’t know how the underlying process works so…) that this is the problem:

(20) if thang.spriteName in ['Ogre M', 'Ogre F']
(21)      thang.type = 'ogre'

in the “component|programming.hasAPI” code


#6

The bug has been fixed. the oasis guardian now has his proper type of “oasis-guardian”