Coded Orders help?


#1

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:
        self.summon(myDict[typeLetter])
        justSummoned = self.built[-1]
    else:
        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?


Feedback: Coded Orders
#2

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

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

#3

Huh. Okay, thanks!

(insert one character here)


#4

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


#5

Weird. This doesn’t work:

self.summon("archer")
decoy = self.built[-1]
self.say(decoy)

But this does:

self.summon("archer")
indices = [0]
decoy = self.built[indices[-1]]
self.say(decoy)

I’ll open another issue: https://github.com/codecombat/aether/issues/151