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

Username:   Password: 
 RegisterRegister   
 How would i go about making a pause button or pause key?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
vdemons




PostPosted: Mon May 23, 2011 5:13 pm   Post subject: How would i go about making a pause button or pause key?

I have been thinking about this for a while, and have done two attempts, both only paused when the button (when made as a button) was held and both didn't work at all (just as a procedure) so I would like to ask how do make a pause button here were my methods.

#1
Turing:

procedure pausing
    var key : string (1) := ""
    key := ""
    if hasch then
        getch (key)
    end if
    if key = ('p') then
        loop
            if key = ('p') then
                exit
            end if
        end loop
    end if
end pausing



and #2
Turing:

procedure pausing
    if chars ('p') then
        loop
            if chars ('p') then
                exit
            end if
        end loop
    end if
end pausing

Sponsor
Sponsor
Sponsor
sponsor
Raknarg




PostPosted: Mon May 23, 2011 5:35 pm   Post subject: RE:How would i go about making a pause button or pause key?

You could still do it the way you have it set up, just you would need to use 2 keys instead of 1. When you press p, it pauses. However, it also unpauses whenever p is pressed. The problem is that the change is so fast, that the user doesn't have time to let go of the p key before the loop begins.
Tony




PostPosted: Mon May 23, 2011 5:46 pm   Post subject: RE:How would i go about making a pause button or pause key?

That's not even the issue (although it often is).
code:

if key = ('p') then
        loop
            if key = ('p') then

If "key = ('p')" is true the first time, it's guaranteed to also be true the second time.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
vdemons




PostPosted: Mon May 23, 2011 5:50 pm   Post subject: RE:How would i go about making a pause button or pause key?

oh I see whats happening now, is there a way to delay the change somehow
vdemons




PostPosted: Mon May 23, 2011 5:56 pm   Post subject: RE:How would i go about making a pause button or pause key?

I tried changing the second p into something else like q but it would pause, and stay paused . . . forever.

if key = ('p') then
loop
if key = ('q') then
Tony




PostPosted: Mon May 23, 2011 6:15 pm   Post subject: RE:How would i go about making a pause button or pause key?

Think about all the conditions that need to hold true for the code to get to the "unpause"/exit part. Can this ever happen?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
RandomLetters




PostPosted: Mon May 23, 2011 10:00 pm   Post subject: RE:How would i go about making a pause button or pause key?

procedure pausing
if chars ('p') then
loop
if chars ('p') then
exit
end if
end loop
end if
end pausing

How do you know what the person is pressing?
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  [ 7 Posts ]
Jump to:   


Style:  
Search: