Posted: Sat Sep 08, 2012 9:38 pm Post subject: Turing Get Statement Timer
What is it you are trying to achieve?
Im trying to make it so the get statement will only accept input for "blank" amount of seconds, when that time is up, it continues the script, but if u finish, it keeps the input in a variable. for later use.
What is the problem you are having?
It seems that the get statement pauses everything else until you are finished typing and hit enter
Describe what you have tried to solve this problem
ive looked around alot on these forums, and havent found anything that works quite the way i want it to
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
loop
var number : int
var random := Rand.Int (1, 100)
put random
get number
if number = random + 1 then
cls
else
cls
put "YOU LOSE!"
delay (1000)
exit
end if
end loop
This is what i have so far, im trying to add the timer in that get statement called "number"
Please specify what version of Turing you are using
I'm using 4.1.1 (the newest)
I Appreciate any help i can get! Thanks guys!
Sponsor Sponsor
Amarylis
Posted: Sat Sep 08, 2012 11:50 pm Post subject: RE:Turing Get Statement Timer
You might want to consider using getch inside a loop for specific amount of time, as opposed to using a get statement.
Tony
Posted: Sun Sep 09, 2012 2:47 am Post subject: RE:Turing Get Statement Timer
getch could also block, unless you specifically check that there's something in the buffer with hasch.
Posted: Sun Sep 09, 2012 9:34 am Post subject: RE:Turing Get Statement Timer
Thanks so far guys, but if you don't mind, could you maybe elaborate, or give an example please? Thanks a bunch!
Insectoid
Posted: Sun Sep 09, 2012 9:57 am Post subject: RE:Turing Get Statement Timer
Well, it's a lot more complicated than just 'get'. Probably a lot more complicated than you expected too.
Basically, you're gonna need a loop that quits after X seconds. Inside that loop, use hasch() to check if a key is pressed. If it is, use getch() to input that key and add it to a string. If the user hits 'enter', save that string, quit the loop and move on. If time runs out, delete the string, quit the loop and move on.
Tony
Posted: Sun Sep 09, 2012 5:05 pm Post subject: RE:Turing Get Statement Timer
backspaces are interesting. What if user deletes more characters than they've entered?
Posted: Sun Sep 09, 2012 5:44 pm Post subject: RE:Turing Get Statement Timer
I actually included that in my original write-up, but it was too long and I figured OP could/should work out the details on his own.
Shadow456732
Posted: Sun Sep 09, 2012 8:45 pm Post subject: RE:Turing Get Statement Timer
Well I've tried as you guys have suggested, but to no avail, it seems I don't really understand how to use the getch or the getchar commands, it's a pretty essential part to the program so it would be nice if I could get it to work
Sponsor Sponsor
Amarylis
Posted: Sun Sep 09, 2012 9:44 pm Post subject: RE:Turing Get Statement Timer
Try first playing around with hasch and getch on their own. Then, play around with timers (Time.Elapsed, etc). Afterwards, try to link the two together, and if you're still having problems, post what you've tried so far.
QuantumPhysics
Posted: Mon Sep 10, 2012 7:27 am Post subject: RE:Turing Get Statement Timer
Turing has an open documention in the interpreter itself. If its the same as python - you can just hit f1 hotkey and the documentation will appear where you can then go to index and type in the command you are struggling with at the top and it will give you a nice explanation of how it works.
Insectoid
Posted: Mon Sep 10, 2012 8:10 am Post subject: RE:Turing Get Statement Timer
Actually, Turing's docs are broken since they just link to Holtsoft which doesn't host it anymore.
Posted: Mon Sep 10, 2012 8:48 am Post subject: RE:Turing Get Statement Timer
Oh sorry, didnt know that, never used turing.
Amarylis
Posted: Mon Sep 10, 2012 7:54 pm Post subject: RE:Turing Get Statement Timer
Turing has compressed HTML docs as well in one of it's folders (no longer have Turing, couldn't tell you the directory)
Shadow456732
Posted: Mon Sep 10, 2012 8:26 pm Post subject: RE:Turing Get Statement Timer
Ok, so , after messing around with getch, getchar, and hatch... My brain melted, and i decided to scratch that and come up with a new method of doing the same thing... Buttons! So after learning how they work, procedure's, calling the buttons variables, and all the other button stuff... I ran into more problems, that i believe can be fixed quite quickly, i just cant seem to find them.
Here's the code i have so far:
import GUI
setscreen("graphics:500;500")
%TITLE AND STARTING CODE
loop
loop
cls
var continue : string
put "Welcome To The Number Game!"
put "Type start to begin"
get continue
if continue = "start" then
cls
exit
else
cls
put "That's Not Start "
delay (1000)
end if
end loop
put "Ok! Lets GO!"
delay (1000)
cls
%END TITLE AND STARTING CODE: Will later add buttons to start, and no if statement will be needed to tell if input was not correct
% ==========================================================================================================================================
%This is the code for the game itself after the titles
loop
var number : int
var random := Rand.Int (1, 100)
put random
% ==================================================================================================
%START BUTTONCODE
%procedures (for buttons)this one is for the answer
var button1text : int := Rand.Int(1, 100)
var button2text : int := Rand.Int(1, 100)
var button3text : int := Rand.Int(1, 100)
var answerbuttontext : int := random + 1
procedure button1procedure
var answer := button1text
end button1procedure
procedure button2procedure
var answer := button2text
end button2procedure
procedure button3procedure
var answer := button3text
end button3procedure
procedure correctanswer
var answer := answerbuttontext
end correctanswer
%Button Names
var randombutton1 : int := GUI.CreateButton (25,25,0,button1text,useranswer)
var randombutton2 : int := GUI.CreateButton (50,50,0,button2text,useranswer)
var randombutton3 : int := GUI.CreateButton (75,75,0,button3text,useranswer)
var answerbutton : int := GUI.CreateButton (100,100,0,answerbuttontext,useranswer)
if answer = random + 1 then
cls
else
cls
put "YOU LOSE!"
delay (1000)
exit
end if
end loop
% END GAME CODE (THIS WILL NOW GO TO TITLE IF YOU LOSE) might add code to give you strikes based on difficulty. As in, counts number of times either "answer" variable
% was wrong, or the time allocated was not met
end loop
Shadow456732
Posted: Mon Sep 10, 2012 8:32 pm Post subject: RE:Turing Get Statement Timer
Forgot to include my problem, in my last post... Sorry, anyways, it seems that, the procedure's themselves don't work. It says that procedure's may only be declared at the program, module, or monitor level... I dont really understand what they mean by that. could use some explanation if you guys don't mind. Also, it says that in all the "randombuttons" that "randombutton1text" is an invalid argument. I'm trying to make it so the value of the variable is displayed as the button name, not so much the variable name.... I've done the same before just not with buttons, and i don't kow why exactly it dosen't work here.
Also, thanks soooo much for all the help guys, sorry if i don't seem like a appreciate it. I'm just concentrating alot on the project it self. It makes a huggee difference to my understanding of turing, so, yeah, thanks again!