[Adventurer] Convenient Enemy


#1

The Mountain level Convenient Enemy is ready for playtesting!

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


#2

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);
        
    }
}

#3
var index = 0;
var type = words[index - 1];

Look at what you’re saying:

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

#4

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

Should be “Listen to them”


#5

Thanks for leaving the gold wand available!


#6

Thanks. WIll fix the typo.


#7

then how am I supposed to get the last word?


#8

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

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

#9

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


#10

oh, I remember, thank you


#11

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?


#12

Have you played levels in Mountains before it?


#13

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


#14

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);
}

#15

Did it! Thanks for the help! :smile:


#16

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);
}

#17

You need the last word, not the third one.


#18

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


#19

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


#20

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