What's wrong?


(trAnc3) #1

Hi, I tried to do this:


736:    for( int [B]i[/B] = 32; [B]i[/B] >= 32 && [B]i[/B] <= 48; [B]i[/B]++ )
737:			{
738:			CG_DrawPic( icon_pos[0] - (icon_extends[0]*0.5f), icon_pos[1] -    (icon_extends[1]*0.5f), [B]i[/B],[B] i[/B], pic );
739:			}


and got these errors:

src\cgame\cg_commandmap.c(736) : error C2143: syntax error : missing ';' before 'type'
src\cgame\cg_commandmap.c(736) : error C2143: syntax error : missing ';' before 'type'
src\cgame\cg_commandmap.c(736) : error C2143: syntax error : missing ')' before 'type'
src\cgame\cg_commandmap.c(736) : error C2143: syntax error : missing ';' before 'type'
src\cgame\cg_commandmap.c(736) : error C2065: 'i' : undeclared identifier
src\cgame\cg_commandmap.c(736) : error C2065: 'i' : undeclared identifier
src\cgame\cg_commandmap.c(736) : error C2065: 'i' : undeclared identifier
src\cgame\cg_commandmap.c(736) : error C2059: syntax error : ')'
src\cgame\cg_commandmap.c(737) : error C2143: syntax error : missing ';' before '{'
src\cgame\cg_commandmap.c(738) : error C2065: 'i' : undeclared identifier
src\cgame\cg_commandmap.c(738) : error C2065: 'i' : undeclared identifier

where I made a mistake?

I hope for answer. Thank you.


(Paul) #2

Does it work if you just do:
for( int i = 32; i >= 32; i++ )

or same errors?

Hmm no doesn’t work

I also tried this but:


			int counting = 32;

			while(counting >= 32 && i <= 48){
				counting++;
				CG_DrawPic( icon_pos[0] - (icon_extends[0]*0.5f), icon_pos[1] - (icon_extends[1]*0.5f), icon_extends[0], icon_extends[1], pic );
			}

gives

\src\cgame\cg_commandmap.c(744) : error C2143: syntax error : missing ‘;’ before ‘type’
\src\cgame\cg_commandmap.c(746) : error C2065: ‘counting’ : undeclared identifier
\src\cgame\cg_commandmap.c(746) : error C2065: ‘i’ : undeclared identifier
\src\cgame\cg_commandmap.c(747) : error C2065: ‘counting’ : undeclared identifier

So that won’t help either


(TomTom7777) #3

Unless you are using a C++ compiler set to permit inline declarations, your variable declaration int i should be at the top of your function or module. That would explain the missing ‘;’ before ‘type’


(Paul) #4

So


void CG_DrawMapEntity( mapEntityData_t *mEnt, float x, float y, float w, float h, int mEntFilter, mapScissor_t *scissor, qboolean interactive, snapshot_t* snap, int icon_size ) {
	int counting = 32;

In combo with


			while(counting >= 32 && counting <= 48){
				counting++;
				CG_DrawPic( icon_pos[0] - (icon_extends[0]*0.5f), icon_pos[1] - (icon_extends[1]*0.5f), icon_extends[0], icon_extends[1], pic );
			}

Isn’t giving warning for me…


(darthmob) #5
int i;
for(i = 32; i >= 32 && i <= 48; i++ )
...

:wink:


(trAnc3) #6

Thanks now it’s working!


(C) #7

TomTom7777 gave the solution, the explanantion of Your error,… but You keep doing Your own thing, making a workaround, while a better way has been proposed.
Why ask in a forum about the error, and not listen to the best advice?..

It is silly to first set a variable value to 32 just before entering a loop, and then check in the loop-conditions if its value >= 32…
btw, the whole loop is crazy anyway: Why execute the same function several times?
The code in the first post at least used the variable i in the loop, but the last posts don’t even do that… It just draws the same image 17 times…


(trAnc3) #8

It is silly to first set a variable value to 32 just before entering a loop, and then check in the loop-conditions if its value >= 32…
btw, the whole loop is crazy anyway: Why execute the same function several times?
The code in the first post at least used the variable i in the loop, but the last posts don’t even do that… It just draws the same image 17 times…

for( [B]i[/B] = 32; [B]i[/B] &gt;= 32 && [B]i[/B] &lt;= 48; [B]i[/B]++ )
  	{
  	CG_DrawPic( icon_pos[0] - (icon_extends[0]*0.5f), icon_pos[1] -    (icon_extends[1]*0.5f), [B]i[/B], [B]i[/B], pic );  // "i" in height and width.
  	}

Idea was to make the growing picture, but it is really silly, because it is growing too fast.


(stealth6) #9

wouldn’t the speed of the growth be effected by the speed of your computer this way?


(C) #10

Yeah… the speed of this sizing is done in a single loop now, and that will performed almost instantly (even on the slowest computer it is not visible, because it is all drawn in the same frame)…

You would have to make some timed drawing mechanism…
Something like this:

int startTime = 0;
int sizingDuration = 1000; //ms
int deltaTime = 0;
float deltaSize = (float)(48-32) / (float)sizingDuration;
int iconSize;

if (startTime==0) startTime = cg.time;
deltaTime = cg.time - startTime;
if (deltaTime<sizingDuration)
    iconSize = 32 + deltaSize*deltaTime;
else
    iconSize = 48;
DrawPic( ..., ..., iconSize,iconSize, pic);

if startTime is set to 0, it starts sizing again from 32 to 48, and it takes a second before it is fully sized…
! code may not work. it’s just to give You an idea of how it can be done…

C…


(trAnc3) #11

Big thanks C! I didn’t know how to do this! I hope your code will work!


(trAnc3) #12

Okay i put code in source:

int startTime = 0;
int sizingDuration = 1000; //ms
int deltaTime = 0;
float deltaSize = (float)(48-32) / (float)sizingDuration;
int iconSize;

and

if (startTime==0){
startTime = cg.time;
deltaTime = cg.time - startTime;
if (deltaTime<sizingDuration) {
iconSize = 32 + deltaSize*deltaTime;
} else {
iconSize = 48;
}
CG_DrawPic( icon_pos[0] - (icon_extends[0]*0.5f), icon_pos[1] - (icon_extends[1]*0.5f), iconSize, iconSize, pic );
}

And when i put the mouse over the icon,
icon instead of growing is just changing location:

What is causing this?
Hmm?


(C) #13

Just changing position hmm…
This code is probably put in some function…
Everytime the function is called, the local variable startTime is set to 0 again…
If You would make it a static var. the value will not be reset on every call to the function…

You just need to find some way to keep it going on sizing while hovering above the icon,
Or to stop the sizing when the mouse moves out of the icon…
But You’ll find that out…

static int startTime = 0;
int sizingDuration = 1000; //ms
float orgSize = icon_extends[0];
float endSize = 48;
int deltaTime = 0;
float deltaSize = (endSize-orgSize) / (float)sizingDuration;
float iconSize;

if (startTime==0) startTime = cg.time;
deltaTime = cg.time - startTime;
if (deltaTime<sizingDuration)
    iconSize = orgSize + deltaSize*deltaTime;
else {
    startTime = cg.time;
    iconSize = orgSize;
}
CG_DrawPic( icon_pos[0]-(iconSize*0.5f), icon_pos[1]-(iconSize*0.5f), iconSize, iconSize, pic );