The Mountain level Convenient Enemy is ready for playtesting!
The first level in the series of levels about str.split(sep)
method.
The Mountain level Convenient Enemy is ready for playtesting!
The first level in the series of levels about str.split(sep)
method.
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];
Haven’t played the level yet, but a typo on the intro screen:
Should be “Listen to them”
Thanks. WIll fix the typo.
then how am I supposed to get the last word?
Have you played levels about arrays? Some of them in the Desert.
var someArray = [1, 2, 3];
var last = someArray[someArray.length - 1];
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
oh, I remember, thank you
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?
Have you played levels in Mountains before it?
I have i just have been away from cc for awhile… what level is it on @Bryukh
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);
}
Did it! Thanks for the help!
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);
}
You need the last word, not the third one.
But isn’t each sentence made up of three words?
Why do you think so? The comment line says about the last word, not about the third one.
You need to use len(soldiers) - 1 to get the last word