Sign in to follow this  
ecr0n

problem...

Recommended Posts

ecr0n    120
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]

Share this post


Link to post
Share on other sites
ProPuke    466
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)

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
ecr0n    120
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this