
-----------------------------------
mike200015
Fri Feb 18, 2005 8:55 pm

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!

-----------------------------------
Flikerator
Fri Feb 18, 2005 9:28 pm


-----------------------------------
Well it would be a little easier if you posted that part of the code so I could modify it for you but;


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
Fri Feb 18, 2005 10:42 pm


-----------------------------------
hey, thanxs very much Flikerator, works great!

-----------------------------------
Flikerator
Fri Feb 18, 2005 10:46 pm


-----------------------------------
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 :D

-----------------------------------
Drakain Zeil
Sat Feb 19, 2005 10:10 am


-----------------------------------
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
Sat Feb 19, 2005 10:43 am


-----------------------------------
Drakain Zeil: Or you could use Input.Flush().

-----------------------------------
mike200015
Sat Feb 19, 2005 10:49 am


-----------------------------------
Drakain Zeil: Or you could use Input.Flush().

What does that do?

-----------------------------------
cycro1234
Sat Feb 19, 2005 12:07 pm


-----------------------------------
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.


% 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


-----------------------------------
Drakain Zeil
Sat Feb 19, 2005 2:53 pm


-----------------------------------
Cool, I never knew about that one.

-----------------------------------
MysticVegeta
Sat Feb 19, 2005 8:39 pm


-----------------------------------
Cool, I never knew about that one.

Theres always
loop
    locate (1, 1)
    put "Press any key to exit"
    exit when hasch
end loop


-----------------------------------
Drakain Zeil
Sun Feb 20, 2005 9:59 am


-----------------------------------
Yes, I know about that, I even said:

Also, hasch can be used for "press any key" ...

My post was in refrence to the Input.Flush
