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.

Dark GDK / Timing in Games

Author
Message
HumanMan
14
Years of Service
User Offline
Joined: 9th Apr 2010
Location:
Posted: 11th Apr 2010 23:17
I want to have a "see how many things you can get in the time limit" kinda game
here is the relevant part of my code :

you can ignore the middle part the aim in the end is to have a timer that reaches 0 when 10s are up but when i take time(current ctime) from start time( stime) i get 20 constantly and also i get this error once the game has quitted ever since the time addition

i need to know a). a totally different take on the time thing
or b). a fix for my time thing
and c). an explanation to the error (image attached)

help??

-James

Attachments

Login to view attachments
Bran flakes91093
16
Years of Service
User Offline
Joined: 13th Sep 2008
Location: Crazy Land
Posted: 11th Apr 2010 23:44 Edited at: 11th Apr 2010 23:47
You're subtracting two pointers here:
dbText(0,0,dbStr(ctime-stime));

I'd use clock() and clock_t from <ctime> if you need seconds. Look to GetTickCount if you need higher resolution timing.
http://www.cplusplus.com/reference/clibrary/ctime/clock/

The error is probably caused by you trying to read memory that is not yours through the use of dbStr when you subtract those two pointers.

By the way, you're causing a memory leak by using dbStr since you don't use it correctly. Use it like this:

Or you can use sprintf:

http://www.cplusplus.com/reference/clibrary/cstdio/sprintf/

"A computer once beat me at chess, but it was no match for me at kick boxing."
Emo Philips
HumanMan
14
Years of Service
User Offline
Joined: 9th Apr 2010
Location:
Posted: 12th Apr 2010 10:35
can you show me the usage please

e.g. a timer that's updated every loop showing seconds since program start

thanks

-James
HumanMan
14
Years of Service
User Offline
Joined: 9th Apr 2010
Location:
Posted: 12th Apr 2010 10:46
actualy i apear to have found a solution

code dump:


hope this helps anyone that has the same problem

-James
MadBit
VIP Member
Gold Codemaster
15
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 12th Apr 2010 14:53
Why you don't use the DarkGDK-Function dbTimer(); The Sample above looks like this ...



With Computers you can solve Problems that you have never befor.

My English is so BAD ;(

Login to post a reply

Server time is: 2024-11-20 01:28:21
Your offset time is: 2024-11-20 01:28:21