Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 how to make a timer and be able to get input running simultaniously
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
aogborne




PostPosted: Fri Apr 08, 2016 12:48 pm   Post subject: 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)


Turing:

% 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
        put "you died"
        delay (1000)
        exit
    elsif 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
Sponsor
Sponsor
Sponsor
sponsor
Dreadnought




PostPosted: Fri Apr 08, 2016 1:50 pm   Post subject: Re: how to make a timer and be able to get input running simultaniously

Unfortunately, get will prevent your program from running until the user hits the Enter key. This means that you can't do what you want with get.

However, you could use functions like input.getchar and input.hasch to read the input from the user and display it to the screen (as if you were using get) and have a timer counting down at the same time.
Mudgato




PostPosted: Sat Apr 09, 2016 11:19 am   Post subject: Re: how to make a timer and be able to get input running simultaniously

Dreadnought @ Fri Apr 08, 2016 1:50 pm wrote:
Unfortunately, get will prevent your program from running until the user hits the Enter key. This means that you can't do what you want with get.

However, you could use functions like input.getchar and input.hasch to read the input from the user and display it to the screen (as if you were using get) and have a timer counting down at the same time.


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




PostPosted: Tue Apr 12, 2016 8:29 am   Post subject: Re: how to make a timer and be able to get input running simultaniously

Dreadnought @ Fri Apr 08, 2016 1:50 pm wrote:
Unfortunately, get will prevent your program from running until the user hits the Enter key. This means that you can't do what you want with get.

However, you could use functions like input.getchar and input.hasch to read the input from the user and display it to the screen (as if you were using get) and have a timer counting down at the same time.



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)?


Turing:


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




PostPosted: Tue Apr 12, 2016 10:05 am   Post subject: Re: how to make a timer and be able to get input running simultaniously

aogborne wrote:
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 char type was added to Turing after getch was).

aogborne wrote:
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 keyboardmodule page for a list of useful constants).
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: