
-----------------------------------
aogborne
Fri Apr 08, 2016 12:48 pm

how to make a timer and be able to get input running simultaniously
-----------------------------------
What is it you are trying to achieve?
i am making a text based game that requires a timer to activate after a command  but also have the user to be able to input information before the time runs out and to see the timer counting down.


What is the problem you are having?
the timers i have been stopping when i ask for input, via loops.

Describe what you have tried to solve this problem
searched timers, have tried loops with delays, loops with Time.Elapsed, procedures. I've tried functions but with the same result although i could be missing something with functions


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)



% this was the idea of the timer i had it working a little cleaner than this
var timer : int 
var command : string


loop
    timer := 2 - (Time.Elapsed div 1000)
   put timer
    if timer  0 then
        get command
        if command = "hi" and timer > 0 then 
            put "you win"
            exit
        end if
    end if
    
    delay (1000)
end loop




Please specify what version of Turing you are using
4.1.1

-----------------------------------
Dreadnought
Fri Apr 08, 2016 1:50 pm

Re: how to make a timer and be able to get input running simultaniously
-----------------------------------
Unfortunately, [tdoc]get[/tdoc] will prevent your program from running until the user hits the Enter key. This means that you can't do what you want with [tdoc]get[/tdoc].

However, you could use functions like [tdoc]input.getchar[/tdoc] and [tdoc]input.hasch[/tdoc] to read the input from the user and display it to the screen (as if you were using [tdoc]get[/tdoc]) and have a timer counting down at the same time.

-----------------------------------
Mudgato
Sat Apr 09, 2016 11:19 am

Re: how to make a timer and be able to get input running simultaniously
-----------------------------------
Unfortunately, 

I'm also facing a similar problem with timers.  Will be searching for other resources and share it back here.  Can you give updates on this thread so we can share solutions?  Thanks.

-----------------------------------
aogborne
Tue Apr 12, 2016 8:29 am

Re: how to make a timer and be able to get input running simultaniously
-----------------------------------
Unfortunately, 


 thanks dreadnought. so i was looking up the tutorials and this is what i have so far... any idea on how to store more than one character at a time. i have a feeling its to do with the loop???
also i just copied the var key line. i'm not sure why its (1)?




var key : string (1) := ""

var timer : int

  loop         
         timer := 10 - (Time.Elapsed div 1000)
         locatexy (maxx div 2, maxy div 2)   
          put timer
             if timer = 0 then
                 put "you loose"  
                 exit
             end if
                if hasch then
                      getch (key)
                end if
        locatexy (1,1)      
        put key
        if key = ("w") then
        put "you win"
        end if
        delay (100)
        cls
        
   
end loop


-----------------------------------
Dreadnought
Tue Apr 12, 2016 10:05 am

Re: how to make a timer and be able to get input running simultaniously
-----------------------------------
also i just copied the var key line. i'm not sure why its (1)?
The type string (1) is a string of length 1 which is basically the same thing as a single character (my guess is that the any idea on how to store more than one character at a time. i have a feeling its to do with the loop???
To store more than one character at a time, use a second string (not of length 1) and every time the use enters a character, add that character to your string.
After that you can start getting fancy by checking if the user hit keys like backspace (see this [tdoc]keyboardmodule[/tdoc] page for a list of useful constants).
