Possible bug with Python - Cannot read property '0' of undefined

So I was recently trying to minimize lines on various levels(in this case ‘enemy mine’) and ended up with the following, which runs correctly and to completion, but gives TypeError: Cannot read property ‘0’ of undefined. It also seems to count the 3 lines as more(?) since it shows in this particular level as being over 5 lines. Is this a bug or simply me not being knowledgeable enough?

test1 = [hero.moveRight(3),hero.moveUp(),hero.moveRight(),hero.moveDown(3),hero.moveRight(2)]
for func, param in test1:
    func(param)

Well, you can just go it by hero.#do somthing with 5 lines, there is no need to do it like this

1 Like

Yes, but this doesn’t explain the bug, you’ve given a workaround, not a permanent fix.
But yes, you are correct that you can execute the code in only two more lines without this error.

-Marmite

I realize the normal solution is only two lines more, but I was trying to see if any further reduction was possible and if there was any way to get the clean or short code achievements for this level. Other than that, the primary focus of the post was not looking for a solution to the level, as it’s relatively well known & simple, but to point out a possible bug and asking about a solution to said bug.

You can maybe do like:

dir = ["right", "up", "right1", "down", "right"]
for i in dir:
    if i == "right":
        #right 3
#ect...
1 Like

This would work in theory but would end up with many more lines than even my expanded multimove function which rather defeats the purpose of that original code. I’ll reiterate that my primary goal is understanding why the TypeError occurs when the code runs successfully and seems to have no issues otherwise.

def multiMove(directions = [], numTiles = [], iterations = int):
    for i in range(iterations):
        for element in range(len(directions)):
            if directions[element] == 'u':
                hero.moveUp(numTiles[element])
            elif directions[element] == 'd':
                hero.moveDown(numTiles[element])
            elif directions[element] == 'l':
                hero.moveLeft(numTiles[element])
            elif directions[element] == 'r':
                hero.moveRight(numTiles[element])
            else:
                hero.say('Invalid Direction Given')
                pass
multiMove(['u','d','l','r'], [1,2,3,4], 5)