time + type at the same time
Author |
Message |
jessie_f
|
Posted: Sun May 14, 2006 6:40 pm Post subject: time + type at the same time |
|
|
HELLOo people
how do you get user input and do the timer thing at the same time.
so i searched high and low for an answer but the only thing i could find was to get a single character each time. so i decided to register =P thing is, i want to save individual words the user types in into an array so that i may *spellcheck* it later. yeh i'm doing a typing game.
yupp.. my turing knowledge is soo limited i am going to fail my ISP or whatever. it's due tomorrow, but there's no way im handing it in on time!
THANK YOU! |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Dan
|
Posted: Sun May 14, 2006 6:54 pm Post subject: (No subject) |
|
|
Well how is your timmer working? It helps to post the code you have when asking for help.
The two methods i whould sugested are:
1. Using the non blocking character functions you talked about and add each letter to a string. Then when they are done go threw the string and break it up in to smaller ones with substrings.
2. Use processes (procs). Thess are functions that will simualte runing two things at the same time. Tho the key here is simualte since if you only have one cpu it is imposable to do two things at once. This route whould probly be more effshent but makes bad things happen if done worng.
You can find more infomtation on proceses and substrings in our tutoral section. |
Computer Science Canada
Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more! |
|
|
|
|
TheOneTrueGod
|
Posted: Sun May 14, 2006 7:00 pm Post subject: (No subject) |
|
|
Hey, welcome to compsci.
#1 This place moves kinda slowly, so posting the day before the ISU generally isn't a good idea
#2 Specific examples, such as code you have tried will help others help you much better.
Allright, onto the advice. Judging by what you said, I believe this is an actual use for processes *gasp*. You could use a process and Time.Elapsed to constantly output the time to the screen, or you could use Input.KeyDown in a clever and well thought out way. Since your short on time, you might want to go for the process way .
I'll try and give some easy examples to follow for each one.
for the process method, you basically just want to:
code: | loop
locate(locationx,locationy)
put maxTimeGiven - (Time.Elapsed - timeStarted)
if maxTimeGiven - (Time.Elapsed - timeStarted) <= 0 then
%Pseudo Code
Set a global boolean to true to indicate that they failed.
stop execution of this process.
end if
end loop |
Unfortunately, with this method, the program would sit there and wait for them to input something before telling them that they failed. (Unless you used a clever and well thought out method against this)
Input.KeyDown method would probably be easier to manage in the long run, and it will be MUCH easier to debug.
Each iteration of the main loop, you would basically check to see if the apropriate key is being pressed, and if it is, then do whatever it is you need to.
Depending on the situation, each method could have its uses, though generally the process one is frowned upon. |
|
|
|
|
|
TheOneTrueGod
|
Posted: Sun May 14, 2006 7:17 pm Post subject: (No subject) |
|
|
Erm, sorry for double posting, but the edit button seems to have dissapeared
Anyways, procs != processes
procs = procedures
Sorry for giving the same information, while I was typing, Hacker Dan kinda posted before me |
|
|
|
|
|
jessie_f
|
Posted: Sun May 14, 2006 7:30 pm Post subject: (No subject) |
|
|
hey thanks guys!
well first of all dan i dont know how to 'non-block characters'. o.0 i just know from this code i found that it's getting individual characters PLUS it's timing but i cant save them.
and theonetruegod, whoa thanks for the long reply. but at this stage i could care less about spellchecking while they're typing hahaha.. ( i am still not going to hand it in on time, teacher's a softie anyways >=] ) i just want to know how you can type + time + save the input like dan's first suggestion.
um i guess here's the code i found on compsci before i registered haha.
code: | View.Set ("offscreenonly")
var input := ""
var _char : string (1)
var lastTime := -1000
var counter := 11
var fontID := Font.New ("Arial:16")
loop
if hasch then
getch (_char)
exit when ord (_char) = 10 %enter
if ord (_char) = 8 then %backspace
if input ~= "" then
input := input (1 .. * -1) %chomp off the last char
end if
else
input += _char
end if
end if
if Time.Elapsed > lastTime + 1000 then %updates every second (1000 milliseconds)
lastTime := Time.Elapsed
counter -= 1
end if
cls
Font.Draw (input, 100, 200, fontID, black)
Font.Draw (intstr (counter), 100, 100, fontID, black)
View.Update
delay (10)
exit when counter <= 0
end loop
|
i forgot whose post it was, but thank you! |
|
|
|
|
|
|
|