Level: Marching Orders

Another level that’s ready for playtesting. Any feedback would be appreciated!

1 Like

Looks pretty cool. A couple of issues:

  1. In the guide you mention the chooseAction() method, but then you don’t have access to it. I understand that the information is discussing how to store values, but it the mention of chooseAction() confused me.
  2. In the default code you say that only some specific commands should be responded to. I think it would be nice if you specifically mentioned the ‘Company Halt!’ command as well.
  3. Might be nice to mention the idea of using a number to represent direction, I could picture many using nested ifs to check current direction and command. Not sure if you want to give that hint or not though.
  4. Along that lines, possibly mentioning the switch statement to replace nested ifs (unless switch is bad practice, not sure there.)

I do like the level though, good stuff!

By the way, completed in 5 lines of code :smile:

Thanks for the feedback! I’ve made changes to address your points 1-3. I think I’ll refrain from mentioning switch since there isn’t currently a snippets section for switch, only for if/else. (Even though my reference solution uses switch.)

Got it down to two lines of CoffeeScript. Fun level, but hard to debug. Since we can’t easily use this.say(), at least until the hover debugger is working better for hear() methods, why not add this.debug() to the APIs so we can use the browser console?

I dig the use of player-code-based randomization here.

Some decorations would be nice. Also, it’s possible for Mace to lead them off the edge of the screen. What about laying down some sort of decorations along the generated path that they should follow, so it makes some visual sense why they are trying to follow this particular marching path?

Could do with some sort of victory playback speedup, plus using letterbox instead of DOM lock.

This one would benefit a lot from recording dialogue and say() audio files. @george blanket Yeti time?

Nice level! I like that this is another level that explains how to control and use the state of your soldiers. To hold on to the direction is essential here, so it a good exercise too.

I was a little bit confused that hear() was listed in the available spells. I made a silly mistake due to this, which was mostly my bad, but I think you should remove hear from the available spells anyway.

A second point is that I prefer checking for undefined using

variable === undefined

rather than

typeof variable === 'undefined'

@dwhittaker: I guess using a switch is good practise here. I ended up making an object and an array

this.changeObj = {'Forward March': 0, 'Right Flank': 1, 
    'About Face': 2, 'Left Flank':3, 
    //'Company Halt!' : 4, 'At ease! Good work!' : 0
};
this.funcs = [this.marchNorth, this.marchEast, 
    this.marchSouth, this.marchWest];

In this way I avoided switches. However, it would be bad to assume that you know all the commands, so when accessing my this.changeObj object I could get undefined. My intuition is that having to handle undefined is bad practise.

@nick Ah, didn’t know about this.debug(). That’s added in now.

Did you actually witness Mace leading them off screen? I had code to prevent that so if it isn’t working I’ll need to take another look at it.

Edit: Also I see that letterbox mode disables the ability to pause or scrub to a different playback time. Is there a way to allow the player to pause or replay sections of the victory playback?

@jacobakkerboom I actually added hear() to the spell list at the request of a playtester who wanted to see the documentation on it. I have some additional stuff up in the guide, but what I really need is some way to have mouse-over documentation for how hear is being used without having it show as an “available spell”. I’ll have to brainstorm a bit on how to handle that.

Also, I have a fuzzy memory that

variable === undefined

has some sort of obscure inappropriate behavior that you’ll almost never run into, but using “typeof” is technically safer. However I can’t remember why that is.

Ah thanks for the reply, It seems you are right. At least the following (long) quote has a lot of upvotes:

If you are interested in knowing whether the variable hasn’t been declared or has the value undefined, then use the typeof operator.

  if (typeof myVar != 'undefined')  

The typeof operator is guaranteed to return a string. Direct comparisons against undefined are troublesome as undefined can be overwritten."

Taken from this answer on SO.

Yes, I did have a time where he leads them off screen (though I could still see his shadow.)

jacob, I actually used an object as well. In python the dictionary’s get function works nicely to avoid undefined:

{‘Left Flank’:1,‘Right Flank’:3,‘About Face’:2}.get(message,0)

1 Like

curious about your 2 lines of coffeeScript. Best I could do was 3 lines in python.

You can mouse over hear(speaker, message, data) in the function signature at the top to see its docs, so yeah, it shouldn’t live in the spell palette here.

@dir = ((@dir ? 0) + {‘Forward March’: 0, ‘Left Flank’: 90, ‘About Face’: 180, ‘Right Flank’: 270}[message]) % 360
@‘march’ + {0: ‘East’, 90: ‘North’, 180: ‘West’, 270: ‘South’}[@dir] unless _.isNaN @dir

ah, my python is similar, I just couldn’t come up with a way to do the error check and the new assignment in the same line.

if (not self.dir): self.dir = 0
self.dir += {‘L’:1,‘R’:3,‘A’:2}.get(message[0],0)
if (message[len(message)-1] != ‘!’): {0:self.marchEast,1:self.marchNorth,2:self.marchWest, 3:self.marchSouth}self.dir % 4

OK, I did indeed mess up the code guarding against going off screen. Should be fixed now, so please let me know if you see Mace lead the squad off the side of the level or see any other odd behavior. Thanks to everyone for finding that.

@nick I’m missing the function signature at the top so you can’t mouse over it to get docs. Is that a problem on my end or your end?

Yeah, that’s my bad; we’ve got to come up with a better design that scales down when the tab is too small. I’ll get it soon.