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
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