Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Expected Primary-Expression before ',' token

Credits go to Timorg for helping out!
This thread is locked; no one can reply to it. rss feed Print
Expected Primary-Expression before ',' token
wolf_wolf17
Member #13,811
December 2011
avatar

I'm creating a platform game and this line in the code is for the map:

rectfill(Buffer, i*BlockSize, j*BlockSize, i*BlockSize + BlockSize, j*BlockSize BlockSize, makecol(0, 255, 255));

The error I get is the title.
Any idea why?

Matthew Leverton
Supreme Loser
January 1999
avatar

What is this:

, j*BlockSize BlockSize,

???

wolf_wolf17
Member #13,811
December 2011
avatar

Here is the whole part of that code.

#SelectExpand
1void Map::Draw(BITMAP *Buffer) 2{ 3 for (int i = 0; i < mapSizeX; i++) 4 { 5 for (int j = 0; j < mapSizeY; j++) 6 { 7 if (MapFile[i][j] == 1) 8 { 9 rectfill(Buffer, i*BlockSize, j*BlockSize, i*BlockSize + BlockSize, j*BlockSize + BlockSize, makecol(0, 255, 255)); 10 } 11 else if (MapFile[i][j] == 2) 12 { 13 rectfill(Buffer, i*BlockSize, j*BlockSize, i*BlockSize + BlockSize, j*BlockSize + BlockSize, makecol(0, 255, 0)); 14 } 15 } 16 } 17}

I put the whole thing as an attachment.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

wolf_wolf17
Member #13,811
December 2011
avatar

That line still has plenty of errors, run it for your self and see the vastness it beholds :P

Timorg
Member #2,028
March 2002

#SelectExpand
1#include <allegro.h> 2 3#define mapSizeX 24 4#define mapSizeY 24 5#define BlockSize 30 6 7int MapFile[mapSizeX][mapSizeY]; 8 9void Draw(BITMAP *Buffer) 10{ 11 for (int i = 0; i < mapSizeX; i++) 12 { 13 for (int j = 0; j < mapSizeY; j++) 14 { 15 if (MapFile[i][j] == 1) 16 { 17 rectfill(Buffer, i*BlockSize, j*BlockSize, i*BlockSize + BlockSize, j*BlockSize + BlockSize, makecol(0, 255, 255)); 18 } 19 else if (MapFile[i][j] == 2) 20 { 21 rectfill(Buffer, i*BlockSize, j*BlockSize, i*BlockSize + BlockSize, j*BlockSize + BlockSize, makecol(0, 255, 0)); 22 } 23 } 24 } 25}

The above code compiles fine, so it seems you have at least fixed that line. :)

edit:
I just had a look at your whole code base, your issue is in "Global.h"

#define ScreenWidth 800
#define ScreenHeight 600
#define BlockSize  40; 

You probably don't want that ; there, as it means that BlockSize is being globally replaced by 40;

Leaving the code looking something like
rectfill(Buffer, i*40;, j*40;, i*40; + 40;, j*40; + 40;, makecol(0, 255, 255));

Which probably isn't what you want.

Macros are not really much of a necessity for c++ in this context. You could consider using const int for these variables.

____________________________________________________________________________________________
"c is much better than c++ if you don't need OOP simply because it's smaller and requires less load time." - alethiophile
OMG my sides are hurting from laughing so hard... :D

wolf_wolf17
Member #13,811
December 2011
avatar

I still get an error on this line:

rectfill(Buffer, i*BlockSize, j*BlockSize, i*BlockSize + BlockSize, j*BlockSize + BlockSize, makecol(0, 255, 255));

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Timorg
Member #2,028
March 2002

I edited my post in the time it took people to post. But I found out where the problem was. My previous post attempts to explain it.

____________________________________________________________________________________________
"c is much better than c++ if you don't need OOP simply because it's smaller and requires less load time." - alethiophile
OMG my sides are hurting from laughing so hard... :D

wolf_wolf17
Member #13,811
December 2011
avatar

Can you compile this again and tell me what errors you get?
And, what do you suggest I do about BlockSize?

Timorg
Member #2,028
March 2002

When the ; is removed, there are no errors. Well I don't link in the allegro library, but the compilation goes fine. Goes off to link with allegro...

-------------- Clean: Release in test ---------------

Cleaned "test - Release"

-------------- Build: Release in test ---------------

Compiling: ..\..\..\Downloads\Platform\Platform\Player.cpp
Compiling: ..\..\..\Downloads\Platform\Platform\camera.cpp
Compiling: ..\..\..\Downloads\Platform\Platform\main.cpp
Compiling: ..\..\..\Downloads\Platform\Platform\map.cpp
Compiling: ..\..\..\Downloads\Platform\Platform\Platform_private.rc
Linking console executable: bin\test.exe
Output size is 18.50 KB
Process terminated with status 0 (0 minutes, 1 seconds)
0 errors, 0 warnings

The 2nd lot of code you posted, that also has a ; issue.

#SelectExpand
1void Map::Draw(BITMAP *Buffer) 2{
3 for (int i = 0; i < mapSizeX; i++);
4 { 5 for (int j = 0; j < mapSizeY; j++) 6 { 7 if (MapFile[i][j] == 1) 8 {
9 rectfill(Buffer, i*BlockSize, j*BlockSize, i*BlockSize + BlockSize, j*BlockSize + BlockSize, 0, 0 makecol(0, 255, 255));
10 } 11 else if (MapFile[i][j] == 2); 12 {
13 rectfill(Buffer, i*BlockSize, j*BlockSize, i*BlockSize + BlockSize, j*BlockSize + BlockSize, 0, 0 makecol(0, 255, 0));
14 } 15 } 16 } 17}

The ; on the 1st marked line is breaking things. The other lines issues relate to a missing comma between 0 and makecol. You might want to look at the function documentation for rectfill and work out what arguments and how many you want to pass to it.

____________________________________________________________________________________________
"c is much better than c++ if you don't need OOP simply because it's smaller and requires less load time." - alethiophile
OMG my sides are hurting from laughing so hard... :D

wolf_wolf17
Member #13,811
December 2011
avatar

Which compiler are you using?
I get an error on the following lines:

if (MapFile[i][j] == 1) //New lookup of 'i' changed for new ISO 'for' scoping

for (int i = 0; i < mapSizeX; i++); //Using obsolete binding at 'i'

 rectfill(Buffer, i*BlockSize, j*BlockSize, i*BlockSize + BlockSize, j*BlockSize + BlockSize, 0, 0 makecol(0, 255, 255)) //Expected Primary-Expression before ',' token x 4,and some other errors similar to that.

I get the: Expected Primary-Expression before ',' token, error on line 32 and 36.

Edit:
Taking out the ; on the first line fixed the first error.

Timorg
Member #2,028
March 2002

I am using MinGW 4.3.2 as my compiler and using CodeBlocks for my IDE.

If you remove the ; from the 1st line I marked, it will mean the scope of i will be what you expect it to be.

As for the errors related to the , I guess you still need to fix your "Global.h".

____________________________________________________________________________________________
"c is much better than c++ if you don't need OOP simply because it's smaller and requires less load time." - alethiophile
OMG my sides are hurting from laughing so hard... :D

wolf_wolf17
Member #13,811
December 2011
avatar

How do you mean Fix?
EDIT:
I revised my code looking for out of place tokens ';', as you said they could brake the code. And I had accidently put one at the end of BlockSize 40. So now it works greatly.
I thank-you. Even if the solution was simple. Next time I will check my code more carefully! ::)

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Timorg
Member #2,028
March 2002

I posted how to fix that problem and what it was doing to your code.

Timorg said:

I just had a look at your whole code base, your issue is in "Global.h"

#define ScreenWidth 800
#define ScreenHeight 600
#define BlockSize  40; 

You probably don't want that ; there, as it means that BlockSize is being globally replaced by 40;

Leaving the code looking something like
rectfill(Buffer, i*40;, j*40;, i*40; + 40;, j*40; + 40;, makecol(0, 255, 255));

____________________________________________________________________________________________
"c is much better than c++ if you don't need OOP simply because it's smaller and requires less load time." - alethiophile
OMG my sides are hurting from laughing so hard... :D

wolf_wolf17
Member #13,811
December 2011
avatar

When you posted it I didn't read the ; in any of it I just skimmed the post, I feel like a D*ck.

Timorg
Member #2,028
March 2002

Well don't forget the "D*ck" feeling, it will become your friend. It was with me for the 1st couple of years of programming. Half my posts here are me misunderstanding the question and posting intelligent and long answers that are not even relevant. So I have complete sympathy for you having that feeling.

____________________________________________________________________________________________
"c is much better than c++ if you don't need OOP simply because it's smaller and requires less load time." - alethiophile
OMG my sides are hurting from laughing so hard... :D

Go to: