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.

DarkBASIC Discussion / A Timer during an IMPUT Command

Author
Message
Flaming Ghost
20
Years of Service
User Offline
Joined: 29th Apr 2005
Location: Um...Right here
Posted: 1st Jun 2005 03:00
I'm making a math game (because I'm bored) I want to make it so that you only have 10 sec. to answer the question. I don't know how to make a timer. Here's basiclly what I'm doing.



Anybody pls help!

Am I dead yet?
zenassem
22
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 1st Jun 2005 07:51 Edited at: 1st Jun 2005 08:11
Sorry but I don't have time to code it right now for you, but this may help you get going...

I believe you are going to need to replace the input command with either inkey$() for a character response, or for reading strings, Entry$(). You can always convert the string data to numerical form with the VAL command.


Note. You can clear the string in the windows message pump, read by Entry$() with the Clear Entry Buffer command.


Although I haven't tested it out, I believe the Input command will halt execution of the rest of your program logic until the enter key is pressed.

-----

As for time...
You will want to look into the the timer command.
Then sete your internal dec time#to be synced with real time. Right now, your code is dependent on syncrate and on delay/wait commands in your loop. That's not going to work.

Keep in mind that return integer=TIMER() retruns time in milleseconds. Thus, 1000 is equal to 1 second. So, if you divided the result by 1000 you would have seconds.

The returned integer is also the internal system time, so you would need to get the system time at the start of the "start of the countdown", and then check how much time has passed each iteration of (pass through) the loop. In this manner the dec time# should only execute if timepassed is => then 1 second

here's some pseudo(fake) code to help.
time1=timer()
time2=timer()
timepassed=(time2-time1)/1000
if timepassed >= 1
dec time#, 1
endif


I hope this makes sense, my head is kind of spinning from work. I can throw up some code later, but this will get you going in the right direction.

Heres an example template of using the timer command to control the game loop rate...


Login to post a reply

Server time is: 2025-05-22 23:51:27
Your offset time is: 2025-05-22 23:51:27