Coded Orders help?

So, I managed to work around the lack of string slicing with some browsing in the Programmaticon V. So now, I’ve managed to write a code, but my units will not move. Here’s my code:

sign = self.findByType("sign")[0]
message = sign.message
myDict = {"a":"archer","s":"soldier","p":"peasant","g":"griffin-rider","P":"paladin"}
justSummoned = None
for i in range(9):
    section = message.slice(5*i,5*(i+1))
    typeLetter = section[0]
    if typeLetter in myDict:
        justSummoned = self.built[-1]
        justSummoned = "Artillery"
    if justSummoned:
        xCoords = int(section.slice(1,3))
        yCoords = int(section.slice(3,5))
        self.command(justSummoned, "move", {"x":xCoords, "y":yCoords})
    i += 1

Can you show me where I’m going wrong?

1 Like

It looks like Python’s negative indexes are not properly implemented yet. Here’s an workaround:

justSummoned = self.built[self.built.length-1]

Huh. Okay, thanks!

(insert one character here)

You probably know this, but for the general public that may be wondering: all the code you input into CodeCombat, independent of your programming language of choice, is ultimately transformed into JavaScript (you can call this “compiling” or “transpiling”).

This is because the only programming language that modern browsers understand is JavaScript, and the whole game simulation runs inside your browser.

The Python code you write in CodeCombat is converted to JavaScript through the Filbert parser.

Your case seems a bit odd now though, as according to this issue, negative indexes are supported. There’s even an unit test that covers this.

Perhaps this bug occurs because self.built is a CodeCombat “built-in” (defined outside of user code)? I’m only guessing now. /cc @nick


Weird. This doesn’t work:

decoy = self.built[-1]

But this does:

indices = [0]
decoy = self.built[indices[-1]]

I’ll open another issue: