Level: The Right Route

I made this to learn a bit about the editor and to have a safe environment to test out how to address arrays. The level is pretty barebones in substance, but I’ll probably be able to flesh out future levels.

The code I have as default needs only minimal changes to get to work, which works nicely, but I’m a total noob at this stuff, so feel free to post better starting plans. I was thinking this would be a level for after someone’s tackled Hunter Triplets and feels comfortable with the concepts in that.

It is a nice level.

I think it is a little empty. Add some trees, or choose another scenario, maybe?
Maybe add some more info and examples to the guide?
It lacks of more level info, and for me, this was important. I thought it was supposed to juke the enemies, until I saw your last comment :wink:

It is a good level for beginners, though. Nice job.

The ogres were always attacking. They seemed retarded, and I think making them smart at the beginning (when we do everything wrong) is a nice approach, instead.Doing it, taunts players, and that’s good! Speaking of taunting, they could also talk some lines and taunt us even more!

Just played it through, I like it!

Regarding its emptiness, probably can push fixing that off until later. We’re going to be investing in more artwork and doodads which should make level building aesthetically easier.

The commentary in the code is a bit heavy. I’d recommend cutting some of it down, and offloading some of the explanation to the docs of the functions, and the guide.

This level maybe feels like it would fit more naturally with a ‘plan’ method. But that would also make it simpler, perhaps too simple when people should be getting used to the ‘chooseAction’ system. Another way to do this would be to just give the soldier a single editable method: ‘chooseTarget’, and have players return either a unit to attack or the sword. Many ways to do this!

Hope that helps!

Thanks for the replies. I think I will move some of the commentary out of the code and into the guide, it seems like people are pretty good about checking it out if need be.

I think changing it to the Tower Defense map would replace giving more level info @F4E. Having the 3 paths set in the map would make it pretty easy to infer that you choose an enemy to go through, rather than some sneaking.

I tried to make the ogres not attack, but it seems that the Component that controls this, ai:Attacks has an issue with the section that says whether they attack when out of range or not. It’s set to false, so they shouldn’t attack fruitlessly, but it doesn’t seem to work and it’s not possible to change to “true”. I will definitely try adding some taunting dialogue in this level or the next one I work on.

@scott: I didn’t go with a plan() method because I wasn’t able to figure out a way to complete it without a for/while loop. My thought process was that if that was required, this would just be an even worse ripoff of Zone of Danger. As for the “chooseAction” system, I had a question: is there any importance to what you name the programmableMethod? I haven’t tested around with it, but can it be nonsense or does it need to be a specific method name?

I’m really curious about making the level with just “chooseTarget”, it sounds like a good idea but I haven’t worked out how one would go about it.

  1. How does the game ID the various Thangs in-game? In scenarios where you can do 'this.say(this.getNearestEnemy())" the soldier will simply say what appears to be the unit’s name. However, when trying to set a target of “Sword” or “Brack”, I just get an ArgumentUndefined error. I’m keenly interested in knowing some more of the inner workings of the various target/enemy gathering methods, I can’t grasp how getNearestEnemy or getEnemies actually function.

  2. I don’t have another question I guess. Your post definitely did help, though! Thanks again for the reply. I will be tinkering around more with this when I wake up.

I’ve updated the level now, condensing it more and hopefully making it a bit clearer on what you’re supposed to do. I finished writing what I wanted to with the guide, hopefully it’s accurate enough, I’m only just learning about arrays myself, after all.

So it’s now very straightforward. I pretty much tried to do as scott described, just editing a single method so that it’s more focused. I ran into some issues with the playback scripting, but I’m not sure if it’s just my browser. Ratio and duration only now make sense to me, duration is what % progress the script goes through and Duration affects how long it takes to go through that chunk of time. Ratio should be renamed or re-described, lol.

Edit: Just remembered a question I had. I was trying to set up a program for the Ogre Brawler so that if the soldier came into attacking range, he’d say something like “rar”, but neither getNearestEnemy or getNearestCombatant were working, even when added to the available spells. What sort of commands are available for enemies/non-soldiers?

What I would do for making them just stand there until Tharin runs up is to set their Sees visualRange to 5 meters, like is done in Munchkin Masher. Then you don’t have to worry about attacksWhenOutOfRange stuff or making them immobile. (By the way, there’s a bug in Treema with the boolean toggles not saving, but you can toggle it and then close its parent to get around that for now.)

chooseAction is the main way that Thangs decide what to do. If you add the Plans Component, then chooseAction() is automatically rewritten to something that just executes the code the player puts in the plan() method. A lot of the ai Components have simple things they do to chooseAction() and that’s all they do. So if you add a random programmableMethod like defrobnosticateWhatzits(), then it will never be called unless you call it from some other programmable method.

I kind of want to make a simpler setTarget() that just takes a string ID that you already know, but it’s unclear how the Thang you’re programming would know that. You can see the code for getEnemies() and such in the Allied Component, but I’m not sure it’ll be very revealing. It gets deep into the internals.

What do you think the name/description for the playback scrub ratio should be?

I’d try HearsAndAggros with a single aggro response of "Rar" on the Brawler, with a short Hears hearing range. But you should be able to do Programmable on any Thang with the isProgrammableDisabled so the player can’t edit it and have it work just the same as any player-controlled Thangs. Just might want to make sure that all the ai Components are removed if you do that. getNearestX() methods are limited by visualRange, so if they returned nothing, that’d be why.

Hope this helps. Was good going through the level editor stuff on Hangout today!

Is the mission just to get the sword or to kill all 3 enemies? I was not able to kill all 3 enemies. Maybe if the ‘attackRange’ was changed when the sword is taken, we would be able to build a new ‘if’ which would allow us to only attack the big ogres when the attackRange is increased.

In this level, the goal is just to kill the one enemy and grab the sword. Your idea sounds pretty good, I might take a look into seeing if I can do that.

I think it is a little too easy to complete. All you need to do change the 2nd line from var enemy = enemies[0]; to var enemy = enemies[2]; and the level is over. I think the original code already there is too much and it should be simplified.

Can you help me with this level?
I try to make not cheat solution (Like var enemy = enemies[2]; ), but i have an error.

var enemies = this.getEnemies();
//Returns an array with all enemies.
var x = 0;
var i = 0;
while (i <= 2) {
    var enemy = enemies[i];

    if (enemy.health > 10) {
        x = x++;
    if (i==3) break; 
enemy = enemies[x];
//Array elements start counting from 0, you can specify an entry using this syntax.
//Check the guide if you're unsure how this evaluates!
if (enemies.length == 3) {
    this.say("I'm coming to get you " + enemy.id + "!");
    if (this.distanceTo(enemy) > this.attackRange)
} else {
    this.say("All clear.");
    this.moveXY(38, 35);    //Sword location

How to break FOR, when i==3.

x = x++ should probably be either x++ or x = x + 1 or x += 1 or ++x.

Also, you don’t need to break depending on i–the while loop will already do that. You want to break when you find an enemy whose health is not greater than 10. So if you added an else-clause to your if-statement to break, then you’d have ended your loop as soon as you saw an enemy you could kill.

Thank you,
But its not solved the problem. Still error Line 8, time 2.2: Cannot read property ‘health’ of undefined

while (i >= 0) {
   enemy = enemies[i];
    if (enemy.health < 10) {
        x = i;

Can you write the right solution, please?

Your approach, with the while-loop:

var x = 0;
var i = 0;
while (i < enemies.length) {
   enemy = enemies[i];
    if (enemy.health < 10) {
        x = i;

Simpler approach using a for-loop:

for (var i = 0; i < enemies.length; ++i) {
    if (enemies[i].health < 10)
enemy = enemies[i];

Thank you, very much.