[Adventurer] Convenient Enemy

The Mountain level Convenient Enemy is ready for playtesting!

The first level in the series of levels about str.split(sep) method.

2 Likes

excuse me, how do you use the word as a type unit, I’m receiving a message saying that type got null.

 if (message) {
        // Words are seaparated by whitespaces.
        var words = message.split(" ");
        // "words" is an array of words from the "message".
        // Get the last word. It's the required type.
        var index = 0;
        var type = words[index - 1];
        // Summon the required unit type.
        hero.summon(type);
        
    }
}
var index = 0;
var type = words[index - 1];

Look at what you’re saying:

var type = words[(0) - 1];
1 Like

Haven’t played the level yet, but a typo on the intro screen:

Should be “Listen to them”

1 Like

Thanks for leaving the gold wand available!

2 Likes

Thanks. WIll fix the typo.

1 Like

then how am I supposed to get the last word?

1 Like

Have you played levels about arrays? Some of them in the Desert.

var someArray = [1, 2, 3];
var last = someArray[someArray.length - 1];
1 Like

completed level without issue. However I wonder if I found a cheat? (check message)

var was left in the Python description text:

var text = "word1,word2,word3"
var words = text.split(",") # ["word1", "word2", "word3"]

(Removed in Patch)


added LUA patch

1 Like

oh, I remember, thank you

1 Like

how do i make my soldiers/archers find their nearest enemy? They either don’t do anything, or go for my nearest enemy. Does anyone have solutions?

1 Like

Have you played levels in Mountains before it?

1 Like

I have i just have been away from cc for awhile… what level is it on @Bryukh

1 Like

Early mountain levels show how to manage by units.
You can command them “defend” their position

for (var i = 0; i < hero.built.length; i++) {
    var unit = hero.built[i];
    // Command the unit to defend the current position.
    hero.command(unit, "defend", unit.pos);
}
1 Like

Did it! Thanks for the help! :smile:

1 Like

It keeps telling me buildXY needs an object, but instead got null. What am I doing wrong?

// Ogres are hiding in woods. Protect the peasants.
// The last word in the peasants' messages are a hint.

for (var x = 8; x <= 72; x += 16) {
    hero.moveXY(x, 22);
    // Peasants know whom to summon.
    var peasant = hero.findNearest(hero.findFriends());
    var message = peasant.message;
    if (message) {
        // Words are seaparated by whitespaces.
        var words = message.split(" ");
        // "words" is an array of words from the "message".
        // Get the last word. It's the required unit type.
        var required = words[2];
        // Summon the required unit type.
        hero.summon(required);
    }
}

for (var i = 0; i < hero.built.length; i++) {
    var unit = hero.built[i];
    // Command the unit to defend the unit's position.
    hero.command(unit, "defend", unit.pos);
}

// Defend the last point yourself:
var enemy = hero.findNearestEnemy();
if (enemy){
    hero.attack(enemy);
}
1 Like

You need the last word, not the third one.

1 Like

But isn’t each sentence made up of three words?

1 Like

Why do you think so? The comment line says about the last word, not about the third one.

2 Likes

You need to use len(soldiers) - 1 to get the last word

2 Likes