Coffeescript seems broken?


#1

It seems like any coffeescript that uses any sort of looping ends up not compiling with the error “cannot read property start of undefined”. Also with certain snippets there’s a “transpiler error” – I believe this happens even with the default code translated into coffeescript.


#2

Yeah, CoffeeScript support is pretty experimental yet. Thanks for the bug report. I’ll track it over here: https://github.com/codecombat/codecombat/issues/1023


#3

Seems to still be buggy. I’m on “Mighty Sand Yak” with this code

loop
    # Use "if" to only move when a yak is less than 10m away.
    enemy = @findNearestEnemy()
    distance = @distanceTo(enemy)
    if distance < 10
    # Move right by adding to your current X position.
    # Use your Sense Stone to access @pos.
        x = @pos.x + 10
        y = @pos.y
    @moveXY(x, y)

Yet my character refuses to move even when the yak is right next to him. And the only hint I get is Move to an {x: number, y: number} position

I’ve tried reloading using the game’s reload button, refreshing using the browser’s refresh button, hard refreshing, and logging out and back in. Nothing is fixing it. Any suggestions?

Also, in previous levels when I attempted CoffeeScript, I got complaints about an unexpected newline character. I had to switch to Python to complete the last half of the Forest world, which defeats the purpose of this for me as I want to learn CoffeeScript.

Edit:
Looking into this further with the JavaScript console, I see the error Simple loop not implemented for CoffeeScript.


#4

You are moving to undefined, undefined in the beginning when there is no yak within range. Try putting the moveXY inside the if body. Because CoffeeScript doesn’t have the simple loop, you’ll also need to do something like this for now to take some action every frame:

    else
        @moveXY @pos.x, @pos.y

#5

Since there is no simple loop, would while true suffice instead?


#6

loop is already part of CoffeeScript as equivalent to while true, actually. We just haven’t implemented the part where it automatically yields if no action is taken. The message the transpiler is giving isn’t saying that loop won’t work at all, just that it can’t prevent an infinite loop error.