Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / What is the best way to make a console input?

Author
Message
Eric Kim
16
Years of Service
User Offline
Joined: 2nd Sep 2008
Location:
Posted: 3rd Sep 2008 06:16
I like to make a console command line for my game, so the user use the '~'key to bring up the console and type commands for debugging.

The console type I'm looking to make is like what you would see in games in like 'DOOM' 'Unreal'... ect

anyone could show me some code of ways doing it that would be great thanks!
RPG
16
Years of Service
User Offline
Joined: 15th Sep 2008
Location:
Posted: 15th Sep 2008 23:55 Edited at: 16th Sep 2008 00:39
C++ Standard Input/Output is your best bet.

If each input item is surrounded by whitespace (blanks, tabs, newlines), the items can be read easily using the extraction operator >> parsing the keyboard input from the cin (terminal input) to a string or character array.



The extraction operator works for numbers (ints, floats), characters (char), and strings (declared as arrays of type char or pointers to type char).

The extraction operator returns a zero value if it encounters a problem (typically, the end of the file). Therefore, it can be used as the test in an if statement or a while loop.

See my next post for useful db functions for scanning specific keys and displaying text.
RPG
16
Years of Service
User Offline
Joined: 15th Sep 2008
Location:
Posted: 16th Sep 2008 00:30 Edited at: 16th Sep 2008 20:27
Use the following to scan for the '~' key press



Then, construct a 'for' loop which displays each key press using 'dbText' at an incremented cursor position. Use dbKeyState to detect a carriage return or button click to send the entered command you have captured into a string 'dbStr' or char array. You should also control the length of the command line and match the string size.

The following snippet will display the scancodes for each key press, not the actual key characters. You can use the dbInkey() function to capture the text into your command string.

Login to post a reply

Server time is: 2024-09-30 05:29:42
Your offset time is: 2024-09-30 05:29:42