Create a Game Console

Started by
24 comments, last by Burnt_Fyr 13 years, 2 months ago
Hi all,
I would create a game console that allow me to type commands to control the game and to have a log view of what the program is doing. I tried to search over the net witouth results, someone could explain me how could I create it and how could I bind it to a key so that if i press a keyboard button it opens the console? Also, how could I have the console like in a normal game binded at the top of the main window?
Advertisement
1. Detect the appropriate keypress for opening the console in your input routine (window procedure, etc.).
2. Create a console window. Redirect appropriate keyboard input to a console input function.
3. Input commands and store in a std::string.
4. Add the input string to, for example, std::vector<std::string> consoleStrings.
5. Display consoleStrings entries in the console window.
6. Pass the input string to a command interpreter to parse and execute as desired.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

I don't understand a thing: how could I bind the console window to the main window?
It depends on what rendering/UI system you're using. It is essentially a multiline textbox with some logic to auto-scroll on add and a textbox for input (or of course your UI system's equivalent). The input will need some sort of interpreter to parse the text and do stuff based on it. Some people wire up Lua, some Python, some just parse it and go. Often times it's pushed into the game-internal scripting system or translated into an internal messaging system.

If you're doing it in-game (which is common), then that UI element just needs to be set top most in the z-order. tilde (or whatever) would then toggle the hide/show of that element. That tends to be a lot cleaner with regards to keeping track of log messages and history while it's not active.

...and depending on what you're looking for, or how far along the game is, you might be better off with more traditional logging/debugging methods.
I'm creating a Win32 C++ application and I have a main window. I would attach the console at the top left of the window. Should i use AllocConsole or should I create a new window with CreateWindowEx command?

I'm creating a Win32 C++ application and I have a main window. I would attach the console at the top left of the window. Should i use AllocConsole or should I create a new window with CreateWindowEx command?

First you'll need to decide whether you want a Windows console (the kind you get when you create a console application), or a typical drop-down, in-game console as is common in many games.

Which of these are you wanting?
the typical drop-down, in-game console. I searched and someone says to use CreateWindow, someone else says to use AllocConsole so I'm really confused

the typical drop-down, in-game console. I searched and someone says to use CreateWindow, someone else says to use AllocConsole so I'm really confused

AllocConsole() creates a separate console window of the type you get in a console application, and CreateWindow() creates a completely new window, neither of which is what you want.

Typically, an in-game console will be handled by the same systems that handle the rest of your game; in other words, it's just 'something else to update and render'. Specifically, it'll usually be rendered over the top of everything else, using an orthographic projection (again, typically).

You should be able to use whatever text rendering method you're using elsewhere. As for the logical part of it, see the suggestions from earlier in the thread.
do you have some examples of how the console could be rendered?

do you have some examples of how the console could be rendered?

Not off hand, no.

But, there's really nothing special about it. If you can render other stuff, you can render a console. A typical approach, for example, would be as follows:

- Render everything but the console (this isn't the only way to do it, but it's probably the easiest)
- Set up an orthographic projection
- Turn off depth testing
- Render a quad for the background
- Render the text using a quad for each character

It's not quite trivial (and can get fairly involved depending on what features you want to support), but it's not too difficult.

If you're still not sure how to proceed, perhaps you could describe which of the above steps you're unsure of. (Also, do you already have a rendering system in place? If so, how do you render the other objects in your game?)

This topic is closed to new replies.

Advertisement