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

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




PostPosted: Fri Feb 18, 2005 8:55 pm   Post subject: getch Help!

In a game i made i have a main screen and on the main screen it says :press c to go to the controls screen
press x to exit
press Enter to start game

but how do i make it so that when the user presses one of the 3 options it does the correspoding action instead of using get where it shows the cursor and then they have to press enter.. If anyone knows how plz help!
Sponsor
Sponsor
Sponsor
sponsor
Flikerator




PostPosted: Fri Feb 18, 2005 9:28 pm   Post subject: (No subject)

Well it would be a little easier if you posted that part of the code so I could modify it for you but;

code:

var window : int                                 %Creates window variable
window := Window.Open ("position:center,center") %Creates window and sets its postion (so we can close it)
var ch : string (1)                              %Variable for getch
loop %Begins loop
    put "Enter corespoding action"               %Replace with proper instructions
    getch (ch)                                   %Gets the keboard input
    if ch = "x" then                             %Checks if "ch" is "x"
        Window.Close (window)                    %Closes the window > Because "ch" was "x"
    elsif ch = "c" then                          %Checks if its "c"
        put "Welcome to control menu..."         %Replace with controls, or with a procedure
    elsif ch = KEY_ENTER then                    %If its not "x" checks if you hits enter
        exit when ch = KEY_ENTER                 %This exits so the game can continue
    end if %ends the if statement
end loop %ends the loop


EDIT - Looks very messy but just copy and paste into turing and it looks neat.
mike200015




PostPosted: Fri Feb 18, 2005 10:42 pm   Post subject: (No subject)

hey, thanxs very much Flikerator, works great!
Flikerator




PostPosted: Fri Feb 18, 2005 10:46 pm   Post subject: (No subject)

No problem. If you need any more help just send me a pm with the problem or a link to a thread with your problem : D

I don't have programming till next year and it might be canceled so I need practise Very Happy
Drakain Zeil




PostPosted: Sat Feb 19, 2005 10:10 am   Post subject: (No subject)

Something interesting to do is use of hasch.

It basicly checks to see if there are any letters not picked up by a get/getch as of yet in the program.

You could have a loop go off animating your menu, and as soon as a key is pressed it doesn't delay and wait for input, it already has input, and will go through and do what that character should do, then go back to animating your menu.

Also, hasch can be used for "press any key" (however, it's worth telling you that you MUST have a getch and assign that value to a variable that is... well, not worth anything except to catch that letter from falling into another "hasch trap" [hasch checks, getch gets, if it's not recived by a get, it's unread, hasch will pass, the character goes into your next getch, and passess every hasch until a getch is there {so like I said, just use getch(null) and don't use that var in the program}]).
Cervantes




PostPosted: Sat Feb 19, 2005 10:43 am   Post subject: (No subject)

Drakain Zeil: Or you could use Input.Flush().
mike200015




PostPosted: Sat Feb 19, 2005 10:49 am   Post subject: (No subject)

Cervantes wrote:
Drakain Zeil: Or you could use Input.Flush().


What does that do?
cycro1234




PostPosted: Sat Feb 19, 2005 12:07 pm   Post subject: (No subject)

The Input.Flush procedure empties the keyboard buffer. It is often used to avoid accidentally reading multiple keystrokes because the user pressed a key for too long, causing autorepeat.

code:

% The "Input.Flush" program.
put "Press and hold a key down.  Then comment out the Input.Flush"
put "and run the program a second time.  The second time the keys"
put "keep echoing after the key is no longer pressed.", skip
loop
    if hasch then
        put getchar ..
        Input.Flush
        delay (100)
    end if
end loop
Sponsor
Sponsor
Sponsor
sponsor
Drakain Zeil




PostPosted: Sat Feb 19, 2005 2:53 pm   Post subject: (No subject)

Cool, I never knew about that one.
MysticVegeta




PostPosted: Sat Feb 19, 2005 8:39 pm   Post subject: (No subject)

Drakain Zeil wrote:
Cool, I never knew about that one.


Theres always
code:
loop
    locate (1, 1)
    put "Press any key to exit"
    exit when hasch
end loop
Drakain Zeil




PostPosted: Sun Feb 20, 2005 9:59 am   Post subject: (No subject)

Yes, I know about that, I even said:

Quote:
Also, hasch can be used for "press any key" ...


My post was in refrence to the Input.Flush
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  [ 11 Posts ]
Jump to:   


Style:  
Search: