problem...

Started by
4 comments, last by ecr0n 19 years, 6 months ago
void updatePlayers() {
	bullet_lag=GetTickCount();

	if(GetTickCount()-bullet_lag<300) {
		if (KEYDOWN(VK_UP))   {
                	//do bullet shooting
		}
	}
}
(i don't know the tag for code... i haven't had to use it before) [Edit: [code] for simple teletype formatting and preserving whitespace, [source] for syntax highlighting, a scrolling window, etc. - Oluseyi] Here is the code snipped that i'm having problems with. I already have the code used to set the limit on the game itself so that it doesn't run too fast and such. I just don't understand as to why this isn't working. i have a predeclaration of DWORD bullet_lag in the main header file and it works with the limiting of the game. i hope that it's just a stupid simple error. the problem with it not having a limit is that currently the bullet is just a pixel with x,y and color. but when you hit keydown because the computer reads it so quickly it reads it as a constant pressing which results in a line of pixels. this code i tried to implement was to allow it so that wouldn't happen, to put a limiter on the button so that it could'nt be pressed but so often. can anyone help? [Edited by - Oluseyi on October 3, 2004 1:08:48 PM]
Advertisement
GetTickCount()-bullet_lag>300 prehaps?
_______________________________ ________ _____ ___ __ _`By offloading cognitive load to the computer, programmers are able to design more elegant systems' - Unununium OS regarding Python
hmm... i tried switching the symbol but then nothing happens...
Well that was your problem since you wanted the event to occour *after* that ammount of time had occoured, not before. If it were set to before then had you waited too long it would never fire.
If it still isnt bring triggered then be sure to check you are initialising bullet_lag to something like 0 @ the start, not some value that is gonna be massively bigger than the current time. (which the random ram address may well be)
_______________________________ ________ _____ ___ __ _`By offloading cognitive load to the computer, programmers are able to design more elegant systems' - Unununium OS regarding Python
void updatePlayers() {	static int bullet_lag = 0;	if(GetTickCount() - bullet_lag > 300){		if (KEYDOWN(VK_UP))   {                	//do bullet shooting                        bullet_lag = GetTickCount();		}	}}


this is what you needed... make sure to initialize the variable, but make it static so it only happends once. also, you have to re-set the timer each time the bullet is fired, and yes, you had the symbol wrong. to check if 300 MS has passed, you do current_time - old_time.. if this is > 300, then 300 or more MS has passed.
FTA, my 2D futuristic action MMORPG
YAY! It worked! Thanks alot. I see what i was doing wrong, i actually didn't really understand the timer thing all that much, now i do. thanks a lot.

laterz

This topic is closed to new replies.

Advertisement