Jump to content
  • Advertisement
Sign in to follow this  
ecr0n

problem...

This topic is 5035 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
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
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!