Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (761)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (845)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Making a console for game (Typing into game actually)  (Read 2620 times)
0 Members and 1 Guest are viewing this topic.
Offline trollwarrior1
« Posted 2013-05-28 13:16:37 »


How does one make a "console" like console in Counter Strike or some other game (CS comes first to my mind when I think about a word console). What I'm interested in particular is typing part. All the rest isn't that confusing to me.

I could make it happen somehow but it would be very messy. Any great suggestions or experiences on typing info into game?
Offline Jimmt
« League of Dukes »

JGO Kernel

Medals: 167
Projects: 5
Exp: 6 years

« Reply #1 - Posted 2013-05-28 16:54:43 »

The console more or less controls an internal scripting language (like Lua). If you don't have this in your game, either implement it or forgo a console completely - like I've said it's mostly for scripting.
Offline Sammidysam
« Reply #2 - Posted 2013-05-28 21:56:31 »

My guess is you have a console class that will get the input, then run it through a class that will separate it into commands and arguments.  Then that class feeds it into the classes for the commands (which will have information on the arguments), and then value is returned to the console class.  From there the console class will print any errors to the console and print any necessary information to the console.  Then it waits for a new input.  My idea on how this works has come from my dream of making a fake Java Operating System in that it's like an operating system but it just runs in your current system, so I've planned out how it will work a lot.  I've never started it, though.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Sammidysam
« Reply #3 - Posted 2013-06-04 16:04:03 »

Sorry for a late response, but I have made a GitHub repository for the project I talked about in the post above and it has a somewhat decent console, but only three commands so far.  Here it is.  I hope it can help you out  Wink
Offline bilznatch

JGO Coder

Medals: 11
Projects: 2
Exp: 4 years

I'm bad, I'm bad, I'm really... really bad T_T

« Reply #4 - Posted 2013-06-09 00:48:37 »

I think Jimmt gave you the best answer. Think about how you would send commands if you were writing an IRC bot or client in Java, or any automated system for that matter, you need to set up an internal "scripting" or command langauge that you can use to access what you need. Say you want to send a command via IRC bot, well you can have a text field that is checked for content, and if that content says something like "!say insert text here" it would parse this text and send to the IRC server the words "insert text here" through the bot. If you want to do this in a game, and don't want to use built in java components you'll need to build your own text container, render the text when typed and only while the menu is opened for the console, (so bind a key that opens the console, then look for input while !console.closed()). So you'll need a console class to check running condition and hold the console object, a set of methods your console can run based on user input, and a script built into the game to access said console object.
At least, that's how I would do it with my LIMITED java experience.

Any more experienced people feel free to correct me or clarify anything I might have said oddly.
Offline CodeHead

JGO Knight

Medals: 52

From rags to rags.

« Reply #5 - Posted 2013-06-09 02:07:07 »

A general approach. Create your console class that implements KeyListener. It should be responsible for rendering the visual representation of your console as well as echoing user input and command processor output to your game's display. Next assign a key to toggling your console's visibility. When the console is turned on, you need to redirect all keyboard input through it, accumulate the keys typed into a StringBuffer as well as render their textural representations to the console, then send the contents of the buffer to the command processor when you detect the appropriate key event (such as the enter key being pressed). You should also listen for a "close console" key combination and react accordingly. Once control has returned from the command processor, grab the results (if any) and render them to the console.

My experience with using a command processor comes from integrating Mozilla Rhino into a non game application, but the principles are pretty much the same. JSR-223 ( should get you started with the basics of scripting a Java application in general.

Off the top of my head, I seem to remember the steps being something like:
  • create an instance of the scripting languages command processor
  • create a context to run your script in -- essentially the same as a namespace or package name
  • tell the command processor what internal class instances that you would like to expose to the scripts and assign them an identifier for the scripts to refer to them by
  • Execute the scripts -- If successful, the internal state of your application will be affected by the contents of your script, if not, the command processor usually throws an exception containing useful information about scripts failure conditions
  • Rinse and repeat.

Be warned though that scripting needs to be thought about carefully. Get familiar with the concepts of Shutters which limit what scripts have access to. Don't directly expose game objects to the command processor; use proxy classes that only have the functionality you want exposed as opposed to exposing an entire "core" class. It may not be a huge deal in single player type games, but it's ripe for exploitation in multi-player ones. Finally don't directly expose the Java language to the scripts unless you're sure you absolutely need to. While not as big of a deal for an internal game console where you control the input, if you're loading up an external script file for something like modding, failure to lock down the language means a malicious scripter can easily bypass your games sandbox, and wreak havoc on a users system.

I will say that I have seen other methods for providing scriptable capabilities to Java applications, but none of them seem as robust or as well tested as the "official way". Scripting is an awesome tool when it makes sense for a project. Just make sure that it adds some value, that you think about the implications and implementations thoroughly, and finally make sure you've implemented whatever security is appropriate for your sandboxed environment.

Arthur: Are all men from the future loud-mouthed braggarts?
Ash: Nope. Just me baby...Just me.
Offline HeroesGraveDev

JGO Kernel

Medals: 382
Projects: 11
Exp: 4 years

┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻

« Reply #6 - Posted 2013-06-09 02:38:30 »

Well, having made a more advanced console with LWJGL, I'll give a few pointers and some generalised code:

Some of it may be hard to understand.

Think of
as a cylinder.
On one side is a printer writing on it. Once the printer writes a line, it turns.
On the opposite side to the printer is a cleaner. Any text that goes through there gets wiped out so it's clean for when it next gets to the printer

Depending on the size of the console, you may need to change the size of

Pages: [1]
  ignore  |  Print  

EgonOlsen (348 views)
2018-06-10 19:43:48

EgonOlsen (342 views)
2018-06-10 19:43:44

EgonOlsen (290 views)
2018-06-10 19:43:20

DesertCoockie (514 views)
2018-05-13 18:23:11

nelsongames (796 views)
2018-04-24 18:15:36

nelsongames (783 views)
2018-04-24 18:14:32

ivj94 (1230 views)
2018-03-24 14:47:39

ivj94 (393 views)
2018-03-24 14:46:31

ivj94 (1057 views)
2018-03-24 14:43:53

Solater (412 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!