What is causing these errors?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

What is causing these errors?

fishboy1887
I have a large amount of errors that are all the same for different methods, but I cannot see for the life of me what is causing the errors.

I know the error is somewhere around here, and I suspect that it has something to do with the array indexing
- In Player.jack (line 37): In subroutine updateBullets: Expected (
- In Player.jack (line 44): In subroutine updateBullets: Expected )

        while (i < 50) {
            if (~(bullets[i] = null)) {
                do bullets[i].update();
   
                // Check for collision or if bullet is off-screen
                let hasHitAlienResult = hasHitAlien(bullets[i]);
                if (hasHitAlienResult) {
                    let bullets[i] = null;
                } else {
                    if ((bullets[i].y) < 0) {
                        let bullets[i] = null;
                    } else {
                        let bullets[newSize] = bullets[i];
                        let newSize = newSize + 1;
                    }
                }
            }
            let i = i + 1;
        }


- In Player.jack (line 63): In subroutine hasHitAlien: Expected (

    method boolean hasHitAlien(PlayerBullet bullet) {
        return invaders.checkCollision(bullet.x, bullet.y);
    }

- In Player.jack (line 103): In subroutine drawLives: Expected statement(do, let, while, return or if)

    method void drawLives() {
        do Output.moveCursor(1, 25);
        do Output.printString("LIVES");
        var int i;
        let i = 0;

        while (i < lives) {
            var int location;
            let location = 10 * 32 + (300 + i * 30) / 16;
            do Memory.poke(16384 + location, 8);
            do Memory.poke(16384 + location + 32, 62);
            do Memory.poke(16384 + location + 64, 127);
            do Memory.poke(16384 + location + 96, 127);
            let i = i + 1;
        }
        return;
    }


I basically have these errors for all of my files, but I imagine once I figure out what is causing the problem then I can solve all of them since the solution will most likely apply to all of them.
Reply | Threaded
Open this post in threaded view
|

Re: What is causing these errors?

pm100
i can tell you whats wrong with the last one - you must have all the var declarations before the code statements
Reply | Threaded
Open this post in threaded view
|

Re: What is causing these errors?

pm100
In reply to this post by fishboy1887
aceess to the fields of an object is not permitted . ie this

bullets[i].y

is not allowed, you have to write a get_y method. see 11.1.5.2 in book

You can obviously extend the langage to allow this

The language does not permit this construct either (alothough its not spacifcially called out, look at syntax table  10.5)

    do array[i].func();

do

    let x = array[i];
    do x.func();


Reply | Threaded
Open this post in threaded view
|

Re: What is causing these errors?

fishboy1887
Ah that makes sense now. Thanks!