Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / How do I make a delay?

Author
Message
Robs
16
Years of Service
User Offline
Joined: 6th Jan 2008
Location: plano tx
Posted: 13th Jan 2008 09:04
I'm trying to add a delay between my bullets when I press the fire button. I can't seem to find a function inside of DB to do anything like that. I tried reading up on the forums about timers, but I can't seem to find that function anywhere either.

Can anyone help point me in the right direction, or maybe show me how to write a timer?
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 13th Jan 2008 13:52
Every time you fire a bullet, store the current time in milliseconds:

LastFire = TIMER()

When the user tries to fire again, check if n milliseconds has passed. If it has, fire again. For example, I'm checking on the space bar here, with a 1 second delay.

TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 13th Jan 2008 13:53 Edited at: 13th Jan 2008 13:56
Timer() is a function which returns a value in milliseconds (thousandths of a second).

T1=Timer()

puts the current value of the PC's timer into the variable T1 which is continually increasing.

In your main loop, you could use:

Elapsed1 = Timer()-T1

which will result in Elapsed1 containing the number of milliseconds elapsed since the initial call to Timer().

If Elapsed1 = 100 Then Gosub FireBullet

will call the subroutine every tenth of a second. (Alter the value to suit the speed you need).

After the Gosub you need to reset the timer so you can get the new elapsed value. You end up with something along the lines of:



Using T1, T2, T3 etc. you can have multiple timers.

The above example is not the most eloquent way to do this, but it's meant only as a simple explanation of the process.

[Edit] Doh! Batvink's post appeared while I was typing my reply so he beat me to it...

TDK_Man

Robs
16
Years of Service
User Offline
Joined: 6th Jan 2008
Location: plano tx
Posted: 13th Jan 2008 21:53
What header contains timer? I can't find it anywhere in GDK
flashing snall
19
Years of Service
User Offline
Joined: 8th Oct 2005
Location: Boston
Posted: 14th Jan 2008 06:17 Edited at: 14th Jan 2008 06:18
or wihout using timer()....
you can just make ur own.



This is my WIP, not even ready for a WIP thread yet though.http://smallgroupproductions.com/
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 14th Jan 2008 09:49
Quote: "What header contains timer? I can't find it anywhere in GDK "


You're in the DB Pro Newcomers forum. Hence, all of these answers are written in DB Pro.

In any Micrososft Studio language, you would use it's own time functionality.
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 14th Jan 2008 16:19
Quote: "you can just make ur own"


The entire reason for the use of Timer() is because you can't make your own!

The code snippet you posted executes at a different speed on your computer to what it does on mine - making it pretty much useless as a delay.

So, if you want the speed of a bullet to be the same on all machines, you use Timer().

TDK_Man

Login to post a reply

Server time is: 2024-11-25 10:39:01
Your offset time is: 2024-11-25 10:39:01