Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (121)
games submitted by our members
Games in WIP (577)
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 819 times)
0 Members and 1 Guest are viewing this topic.
Offline trollwarrior1
« Posted 2013-05-28 13:16:37 »

Hello,

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: 136
Projects: 4
Exp: 3 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

Senior Duke


Medals: 8
Projects: 2
Exp: 1 year


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: 41


From rags to riches...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 (http://docs.oracle.com/javase/6/docs/technotes/guides/scripting/) 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: 269
Projects: 11
Exp: 2 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:

http://pastebin.java-gaming.org/a6a718a0a6c

Some of it may be hard to understand.

Think of
lines[]
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
lines[]
.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

theagentd (19 views)
2014-10-25 15:46:29

Longarmx (52 views)
2014-10-17 03:59:02

Norakomi (45 views)
2014-10-16 15:22:06

Norakomi (34 views)
2014-10-16 15:20:20

lcass (39 views)
2014-10-15 16:18:58

TehJavaDev (68 views)
2014-10-14 00:39:48

TehJavaDev (68 views)
2014-10-14 00:35:47

TehJavaDev (60 views)
2014-10-14 00:32:37

BurntPizza (74 views)
2014-10-11 23:24:42

BurntPizza (45 views)
2014-10-11 23:10:45
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org 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‑gaming.org
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!