
-----------------------------------
Shadow456732
Sat Sep 08, 2012 9:38 pm

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!

-----------------------------------
Amarylis
Sat Sep 08, 2012 11:50 pm

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
Sun Sep 09, 2012 2:47 am

RE:Turing Get Statement Timer
-----------------------------------
getch could also block, unless you specifically check that there's something in the buffer with [tdoc]hasch[/tdoc].

-----------------------------------
Shadow456732
Sun Sep 09, 2012 9:34 am

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
Sun Sep 09, 2012 9:57 am

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
Sun Sep 09, 2012 5:05 pm

RE:Turing Get Statement Timer
-----------------------------------
backspaces are interesting. What if user deletes more characters than they've entered? ;)

-----------------------------------
Insectoid
Sun Sep 09, 2012 5:44 pm

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
Sun Sep 09, 2012 8:45 pm

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

-----------------------------------
Amarylis
Sun Sep 09, 2012 9:44 pm

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
Mon Sep 10, 2012 7:27 am

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
Mon Sep 10, 2012 8:10 am

RE:Turing Get Statement Timer
-----------------------------------
Actually, Turing's docs are broken since they just link to Holtsoft which doesn't host it anymore. 

Luckily, compsci.ca has a copy [url=http://compsci.ca/holtsoft/doc/]here.

-----------------------------------
QuantumPhysics
Mon Sep 10, 2012 8:48 am

RE:Turing Get Statement Timer
-----------------------------------
Oh sorry, didnt know that, never used turing.

-----------------------------------
Amarylis
Mon Sep 10, 2012 7:54 pm

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
Mon Sep 10, 2012 8:26 pm

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 :D"
    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) 




%ButtoncodeEnd
% ==================================================================================================



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
Mon Sep 10, 2012 8:32 pm

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! :)

-----------------------------------
Insectoid
Mon Sep 10, 2012 10:09 pm

RE:Turing Get Statement Timer
-----------------------------------
You can't declare a procedure inside a loop.

-----------------------------------
QuantumPhysics
Tue Sep 11, 2012 7:37 am

RE:Turing Get Statement Timer
-----------------------------------
Is a procedure in turing the same as a function in C/C++?

-----------------------------------
Raknarg
Tue Sep 11, 2012 9:43 am

RE:Turing Get Statement Timer
-----------------------------------
Yes. In turing, they have both procedures and functions, but the difference is taht a function will produce a result at the end, where a prodecure simply ends. I believe in C++ when someone wants to accomplish that they make function that just results 0 and does nothing with it.

It's not necessary, but I think the creators of turing thought it would make more sense to make separate options.

-----------------------------------
2goto1
Tue Sep 11, 2012 10:01 am

RE:Turing Get Statement Timer
-----------------------------------
The thought process for Turing having functions and procedures as separate entities can be summarized in the function help documentation found at http://compsci.ca/holtsoft/doc/function.html. 

Here is the relevant portion:
In principle, a function (1) should not change any variables outside of itself (global variables) or (2) should not have var parameters. In other words, it should have no side effects. The original implementation prevented (1) and (2) and thereby prevented function side effects. Current implementations of Turing do not enforce this restriction.

Some languages today still actually enforce this type of rule. But I'm only familiar with database languages enforcing this type of rule today, typically for database query optimization / performance purposes.
