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

Username:   Password: 
 RegisterRegister   
 getch & hasch
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
appling




PostPosted: 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
Sponsor
sponsor
Tony




PostPosted: 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
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Mazer




PostPosted: 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




PostPosted: 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




PostPosted: 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
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
appling




PostPosted: Sat Nov 22, 2003 9:37 pm   Post subject: (No subject)

but how to change 2 to 1 then
Tony




PostPosted: 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
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Blade




PostPosted: 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
Sponsor
sponsor
appling




PostPosted: Sat Nov 22, 2003 11:15 pm   Post subject: (No subject)

thanks i get it
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  [ 9 Posts ]
Jump to:   


Style:  
Search: