Author |
Message |
vdemons
|
Posted: 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
|
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Raknarg
![](http://compsci.ca/v3/uploads/user_avatars/3745510004d8be6689b92f.jpg)
|
Posted: 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. |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: 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. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
vdemons
|
Posted: 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 |
|
|
|
|
![](images/spacer.gif) |
vdemons
|
Posted: 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 |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: 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? |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
RandomLetters
|
Posted: 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? |
|
|
|
|
![](images/spacer.gif) |
|