Sign in to follow this  
stampede247

C# Console Window

Recommended Posts

Hey guys I'm new to the forum so sorry if this is a re-post or anything like that. So I was working on trying to make a console window for my games. I'm working in XNA but that shouldnt matter much for what I'm doing. Basically what I want is to make a way that you can edit and check on variables in game by typing stuff into this console like "get variable1" or "variable1 = 10". So I was wondering if there was a way to process this string name "variable1" into a reference to variable1 in my code without specifically going 'if (name == "variable1") { return variable1; }' because I want to make the console as versatile as possible.

Any ideas on what to do? Let me know if you need more info.Thanks in advance!

p.s. Oh also if there is a way to get a reference this way that also includes a class name or namespace for example: "StaticClass.varaible1 = 10". If not I can work around that.

Share this post


Link to post
Share on other sites
If the functionality you want is simple, you could probably roll your own parser and use reflection to capture the class and member names. Read up on reflection in C#, you'll find it's pretty powerful.

Here's some stuff to maybe get you started: [url="http://www.dotnetperls.com/reflection"]http://www.dotnetperls.com/reflection[/url]

If you wanted a more general or extinsible solution, such as scripting, perhaps you could leverage something like CS-Script.

Share this post


Link to post
Share on other sites
Unless I was using reflection every iteration in a tight loop somewhere, I wouldn't worry about perfomance. I probably wouldn't worry about it anyway, until it became a problem.

What the OP seems to indicate is that his parser would execute only in response to typed input, and would be fairly simple. I highly doubt that the performance characteristics of reflection would come into play under such a scenario.

Share this post


Link to post
Share on other sites
I found this to be an interesting start at writing a console:

[url="http://bittermanandy.wordpress.com/2008/07/28/efficient-development-part-two/"]http://bittermanandy.wordpress.com/2008/07/28/efficient-development-part-two/[/url]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this