0

Ok, so I really can't figure this one out. I defined an array, playerPos, like this:

int[] playerPos = new int[]{32, 32};

and the first number is the x value, second is the y value. But, when I try to use it to define a rectangle, I get a syntax error here:

        for (int x = 0 ; x < 64; x++) {
        for (int y = 0 ; y < 64; y++) {
            switch(map[x][y]) {
            case 1:
                mapRects[x][y] = new Rect(x - playerPos[0])*64, (y - playerPos[1])*64, ((x - playerPos[0])*64)+64, ((y - playerPos[1])*64)+64);
                break;

            case 2:
                mapRects[x][y] = new Rect(x - playerPos[0])*64, ((y - playerPos[1])*64)-64, ((x - playerPos[0])*64)+64, ((y - playerPos[1])*64)+64);
                break;
            }
        }
    }

Wherever I say new Rect(), it gives me a syntax error on all the commas saying

Syntax error on token ",", [ expected

and on the last number, it says

Syntax error, insert "]" to complete Expression

I have no idea what is wrong. Help?

2 Answers 2

5

It is a parentheses problem:

new Rect(x - playerPos[0])*64 ...

You probably need to add an opening one like this:

new Rect((x - playerPos[0])*64 ...
Sign up to request clarification or add additional context in comments.

3 Comments

Wow, that is probably the dumbest mistake I have ever made in my life. Even more, I didn't notice. Thanks so much!
Everyone does it. Multiple times. The only trick I can think of that helps is to write parentheses in a pairs when you open the first one. If you do that every time, you'll never go screwy. So type str(), first, then add the expression inside, say str(10.0/2.1). The only annoyance is having to cursor back. Some IDEs auto open parentheses and brackets in pairs, but I find them mostly annoying with where they then place the cursor. I use vim. Vim rocks.
Oh and maybe you want to ACCEPT THE ANSWER, spng453. Thanks.
1

You are missing a parenthesis on your Rect.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.