Computer Science Canada Timer working alongside a get statement |
Author: | GenesisXCS [ Tue Apr 27, 2010 11:45 am ] |
Post subject: | Timer working alongside a get statement |
Greetings to everyone =) The program I am making is a Math Game. It is in Text Form right now, and I am planning to migrate it (not sure if that's correct terminology, w/e) to graphics mode. (that is still under plan). What actually happens are simple multiplication, division, addition, subtraction are asked, and the user needs to input an answer within the timelimit. The faster, the more points; the higher the answer, the more points. However, I cannot get a timer to work alongside a get statement (the processing halts as the program waits for user input). Is there an alternate way? Even if this doesn't work, can I get a code that times how long it takes for a user to input the answer? What is it you are trying to achieve? I am trying to make a timer that runs in parallel (if you may) with a get statement. I am not sure if this is possible. I have another plan that I think may work, but I am not totally sure yet. Is it possible for the program to check for userinput every loop; so fast that we don't know that it is even checking, rather than halting the whole program waiting for an input?? What is the problem you are having? Program halts as soon as the program waits for user input. Describe what you have tried to solve this problem I've (kind have) played around with the TimeElapsed code ( I believe). I am not totally sure how the various Time Functions work. Some go by the frequency of the CPU (I think), while some go by the clock. Post any relevant code (You may choose to attach the file instead of posting the code if it is too long) Don't have anything right now worth mentioning. (There is a get statement) Please specify what version of Turing you are using Turing 4.1 Thanks in advance, I really appreciate any help I can get. This is my first game Cheers GenesisXCS EDIT: The plan was in graphics mode, when a graphic hits the bottom of the screen such as (if x_arrow=25 then points := 0) or something like that. |
Author: | USEC_OFFICER [ Tue Apr 27, 2010 11:53 am ] |
Post subject: | RE:Timer working alongside a get statement |
Time.SinceLast. Look it up. It should be what you are looking for. |
Author: | TheGuardian001 [ Tue Apr 27, 2010 12:21 pm ] | ||
Post subject: | Re: RE:Timer working alongside a get statement | ||
USEC_OFFICER @ Tue Apr 27, 2010 11:53 am wrote: Time.SinceLast. Look it up. It should be what you are looking for.
I believe you mean time_delaysincelast. However I'm pretty sure that won't do what they want. What that will do is make sure that inputting the answer takes at least 10 seconds (as an example). It won't, however, actually tell you how long they took to complete answering the question, nor stop them from going over the allotted time while answering. What you could do would be to use a loop in combination with hasch and with Time.Elapsed. The process for doing so is basically: 1)right before the question starts, create a variable with the value of Time.Elapsed. This will tell you what time they started answering the question at (in milliseconds). 2)Start a loop. This loop will get input using getchar(), and check how long they've had to answer using Time.Elapsed. It should look something like:
The hasch will see if they're entering anything, and currentTime - startTime will give you the time they've had to answer. If they go over the time limit (in this case 10000 mS, or 10 seconds), you exit the loop. You should also exit the loop if the last character of ans is KEY_ENTER |
Author: | USEC_OFFICER [ Tue Apr 27, 2010 2:53 pm ] |
Post subject: | RE:Timer working alongside a get statement |
That's what I meant (Though that's moot point now.) I never really used the Time. Functions though. Oh well. |
Author: | andrew. [ Tue Apr 27, 2010 3:34 pm ] | ||
Post subject: | RE:Timer working alongside a get statement | ||
An easy way to do it is to get the time before the get and then after. After you subtract the two, you have to time it took to run. This is similar to what TheGuardian said.
|
Author: | copthesaint [ Tue Apr 27, 2010 8:38 pm ] | ||
Post subject: | Re: Timer working alongside a get statement | ||
Heres a different way to do this:
Its all commented so it should be easy enough to follow through. I thought it was a good break making this, until turing freaking had a meltdown and shut down 3 times in row :/ unexpected environment errors... FTL |
Author: | GenesisXCS [ Wed Apr 28, 2010 1:51 pm ] |
Post subject: | RE:Timer working alongside a get statement |
Thank you all for your lengthy and EXTREMELY helpful responses. This is a good starting point for me, and I will definitely put this into practise; once I absorb everything you've written down. +D Thanks again! |