C ++ expected primary expression

I am working on a very simple game (essentially an ice breaking puzzle), at the moment all things are in one file and the only level is completely empty of any obstacle. It throws several errors. My current annoyance is the expected primary expression error, can anyone tell me how to fix it (it drops to line 99)?

Everybody is here,

#include <allegro.h>

BITMAP* buffer;

int x = 15;
int y = 11;

int tempX = 15;
int tempY = 11;

//This will be our background, 1 = clouds, 2 = brick, 3 = floor
int map[24][32] = {{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,2,3,3,3,3,3,3,3,3,3,2,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,2,3,3,3,3,3,3,3,3,3,2,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,2,3,3,3,3,3,3,3,3,3,2,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,2,3,3,3,3,3,3,3,3,3,2,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,2,3,3,3,3,3,3,3,3,3,2,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,2,3,3,3,3,3,3,3,3,3,2,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,2,3,3,3,3,3,3,3,3,3,2,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,2,3,3,3,3,3,3,3,3,3,2,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,2,3,3,3,3,3,3,3,3,3,2,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}};

//This will contain all the objects, 100 = player
int objMap[24][32] = {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,100,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};

void setupGame(){

     buffer = create_bitmap( 640, 480);

    for (int i = 0; i <= 24; i++){

        for( int t = 0; t <= 32; t++){

            if( map[i][t] == 1) rectfill( buffer, t * 20, i * 20, (t + 1) * 20, (i + 1) * 20, makecol( 128, 255, 255));
            else if( map[i][t] == 2) rectfill( buffer, t * 20, i * 20, (t + 1) * 20, (i + 1) * 20, makecol( 255, 128, 0));
            else if( map[i][t] == 3) rectfill( buffer, t * 20, i * 20, (t + 1) * 20, (i + 1) * 20, makecol( 0, 0, 255));

           }       

    }

    for (int i = 0; i <= 24; i++){

        for( int t = 0; t <= 32; t++){

            if( objMap[i][t] == 100) circlefill( buffer, (t * 20) + 10, (i * 20) + 10, 10, makecol( 255, 255, 0));

           }       

    }

    draw_sprite( screen, buffer, 0, 0);

}

void movePlayer(){

     tempX = x;
     tempY = y;

     if ( key[KEY_UP] && map[y - 1][x] == 3){
          for ([y - 1][x] == 3; --y){  // these lines are the ones            
              }
              }

     else if( key[KEY_DOWN] && map[y + 1][x] == 3){
          for ([y + 1][x] == 3; ++y){
              }
              }

     else if( key[KEY_RIGHT] && map[y][x + 1] == 3){
          for ([y][x + 1] == 3; ++x){
              }
              }

     else if( key[KEY_LEFT] && map[y][x - 1] == 3){
          for ([y][x - 1] == 3; --x){
              }
              }

     acquire_screen();

     rectfill( buffer, tempX * 20, tempY * 20, (tempX + 1) * 20, (tempY + 1) * 20, makecol( 255, 0, 0));

     circlefill( buffer, (x * 20) + 10, (y * 20) + 10, 10, makecol( 255, 255, 0));

     draw_sprite( screen, buffer, 0, 0);
     release_screen();

     rest(20);
}

int main(){

    allegro_init();
    install_keyboard();
    set_color_depth(16);
    set_gfx_mode( GFX_AUTODETECT, 640, 480, 0, 0);

    setupGame();

    while( !key[KEY_ESC]){

           modePlayer();

    }

    return 0;

}

END_OF_MAIN();

      

and here's the section that breaks down;

void movePlayer(){

     tempX = x;
     tempY = y;

     if ( key[KEY_UP] && map[y - 1][x] == 3){
          for ([y - 1][x] == 3; --y){              
              }
              }

     else if( key[KEY_DOWN] && map[y + 1][x] == 3){
          for ([y + 1][x] == 3; ++y){
              }
              }

     else if( key[KEY_RIGHT] && map[y][x + 1] == 3){
          for ([y][x + 1] == 3; ++x){
              }
              }

     else if( key[KEY_LEFT] && map[y][x - 1] == 3){
          for ([y][x - 1] == 3; --x){
              }
              }

      

this is for the lines he doesn't like.

thanks if you can help.

0


source to share


4 answers


This can help:



void movePlayer(){

    tempX = x;
    tempY = y;

    if (key[KEY_UP] && map[y - 1][x] == 3)
        for ( ; map[y - 1][x] == 3; --y){              
        }

    else if(key[KEY_DOWN] && map[y + 1][x] == 3)
        for ( ; map[y + 1][x] == 3; ++y){
        }

    else if(key[KEY_RIGHT] && map[y][x + 1] == 3)
        for ( ; map[y][x + 1] == 3; ++x){
        }

    else if(key[KEY_LEFT] && map[y][x - 1] == 3)
        for ( ; map[y][x - 1] == 3; --x){
        }

      

+3


source


What's going on here?

[y - 1][x] == 3

      



You meant:

 map[y - 1][x] == 3

      

+6


source


The for () element takes up three parts, separated by a ';'

for(<init>;<test>;<post>)
{
}

      

Any of these three parts can be empty, but ';' should be there.

You are also missing an object that you must index from the test portion of each for () statement.

for(; map[BLA][BLA] == <VALUE>;<INC>)

      

+4


source


Your "for" loops are missing a section. There are usually three parts: initialization, condition, and post-iteration operation. From what I can tell you have the last two, but no initialization. The compiler currently interprets your first "for" loop, for example:

  • Check 3 against [y-1] [x]
  • While 0! = (Result of decrement y) ...
  • Do something

I think what you mean is:

  • Let's assume everything is initialized
  • While 3 == [y-1] [x] ...
  • Do whatever and decrease y after each iteration

If so, it should look like this:

for (; [y-1][x]==3; --y)
{
    // do whatever
}

      

This applies to all of your "for" loops.

Another problem is that you are not using an array variable, but simply using index offsets. Do you mean "map [y-1] [x]"?

+1


source







All Articles