Author |
Message |
appling

|
Posted: Sat Nov 22, 2003 4:12 pm Post subject: getch & hasch |
|
|
i am worried about my homework. i don't know getch & hasch clearly.So is there anyone can help me??
how to use getch & hasch. |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Tony

|
Posted: Sat Nov 22, 2003 4:31 pm Post subject: (No subject) |
|
|
getch grabs a single character from the input buffer.
code: |
var c:string(1)
getch(c)
put c
|
hasch returns true if there's anything in input buffer waiting to be processed. It is generally used to skip getch so that program continues even without user's input.
code: |
var c:string(1)
loop
if hasch then
getch(c)
locate(1,1)
put "you've pressed ",c
delay(1000)
end if
locate(1,1)
put "waiting..."
end loop
|
|
Tony's programming blog. DWITE - a programming contest. |
|
|
|
 |
Mazer

|
Posted: Sat Nov 22, 2003 4:33 pm Post subject: (No subject) |
|
|
use getch to get a character. like this:
code: |
var character : string (1) %<- the (1) is important
getch (character)
|
use hasch to see if a character has been pressed. like this:
code: |
loop
exit when hasch
put "wheeeee loop!"
end loop
put "aack! you pressed a character!"
|
|
|
|
|
|
 |
appling

|
Posted: Sat Nov 22, 2003 4:44 pm Post subject: (No subject) |
|
|
so,if i have a graphics program that have 2 scene, and i want to change the scene A to scene B immediately by pressing the keyboard, also later change the scene B to scene A immediately by pressing the keyboard.
what can i do?? |
|
|
|
|
 |
Tony

|
Posted: Sat Nov 22, 2003 6:09 pm Post subject: (No subject) |
|
|
you can do
code: |
var c:string(1)
loop
if hasch
%key has been pressed
getch(c) %clears the buffer
drawScene2
end if
end loop
|
|
Tony's programming blog. DWITE - a programming contest. |
|
|
|
 |
appling

|
Posted: Sat Nov 22, 2003 9:37 pm Post subject: (No subject) |
|
|
but how to change 2 to 1 then |
|
|
|
|
 |
Tony

|
Posted: Sat Nov 22, 2003 9:46 pm Post subject: (No subject) |
|
|
you exit your loop and start another one, this time waiting to draw scene1 |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
 |
Blade
|
Posted: Sat Nov 22, 2003 10:23 pm Post subject: (No subject) |
|
|
you could also just use one loop and use a boolean var..
code: | var switch:boolean:=false
var c:string(1)
loop
if hasch
%key has been pressed
getch(c) %clears the buffer
if switch then
drawScene2
switch:=false
else
drawScene1
switch:=true
end if
end if
end loop |
|
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
appling

|
Posted: Sat Nov 22, 2003 11:15 pm Post subject: (No subject) |
|
|
thanks i get it |
|
|
|
|
 |
|