Why is this not working?


(DiaZ) #1

Be warned I am a RTCW coding noob (and I haven’t touched any C in 3 years), but I wonder why this isn’t working? It’s suppossed to turn distance fog on/off fast (in 260 msec) each 6 seconds, to create a lightning effect on a fogged sky. Bet I don’t even need to have 2 functions, but still, shouldn’t it be working? :confused:

/*

CG_DrawStLightning

*/

static void CG_DrawStLightning (void)
{
int flashTime;

flashTime = cg.time + 260;

if ( cg.time >= flashTime )
{
	trap_Cvar_Set("r_wolffog", "1");
}

}

/*

CG_DrawStormEffect

*/

static void CG_DrawStormEffect (void)
{
int nextTime = 0;

if ( cg.time == nextTime )
{
	trap_Cvar_Set("r_wolffog", "0");	
	CG_DrawStLightning();
	nextTime = nextTime + 6000;
}

}

CG_DrawStormEffect is being called in CG_DrawActive. All functions are in cg_draw.c.

<font size=-1>[ This Message was edited by: DiaZ on 2002-10-03 18:02 ]</font>


(digibob) #2

You cant gaurantee that cg.time will EVER be equal to nexttime, alwys do a check to see if the time has passed, instead.


(DiaZ) #3

Erm… How would I do that? Sorry for my n00bness here, but I still don’t know much about RTCW’s functions, structures and variables and what they do/are… Isn’t cg.time the time passed on a level in milliseconds? This might be where my confusion is…


(digibob) #4

if ( cg.time == nextTime )

use

if ( cg.time >= nextTime )

cg.time IS in milliseconds, but you have no way of knowing whether it will get to this function with any specific value, the only thing you SHOULD be able to gaurantee is that it will get back to this function at some point in time, so you should be checking to see if nexttime is now or has passed.


(DiaZ) #5

Thanks for the help, it’s working now. The problem was that cg.time was starting at 2000 or so when the level was loaded, so the code was not being executed at all…