Jump to content

  • Log In with Google      Sign In   
  • Create Account


C# Console Window


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 stampede247   Members   -  Reputation: 100

Like
0Likes
Like

Posted 05 April 2012 - 03:20 PM

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.

Sponsor:

#2 laztrezort   Members   -  Reputation: 950

Like
0Likes
Like

Posted 05 April 2012 - 04:24 PM

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: http://www.dotnetperls.com/reflection

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

#3 timthereaper   Members   -  Reputation: 101

Like
0Likes
Like

Posted 09 April 2012 - 03:49 PM

From what i understand, using System.Reflection functions takes a relatively long time to execute. If you're concerned with performance, you might want to consider that.
"Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law."

-- Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid

#4 laztrezort   Members   -  Reputation: 950

Like
0Likes
Like

Posted 09 April 2012 - 06:25 PM

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.

#5 Moe   Crossbones+   -  Reputation: 1235

Like
0Likes
Like

Posted 09 April 2012 - 09:13 PM

I found this to be an interesting start at writing a console:

http://bittermanandy.wordpress.com/2008/07/28/efficient-development-part-two/




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS