This project is read-only.

How to use Xna Console with something other than IronPython

If you want to use something other than IronPython for your console, such as IronScheme, Lua, or some other script language you've designed yourself, just follow the example of the PythonInterpreter class. All that's required is that you know 2 methods of the XnaConsole class, Prompt(), and WriteLine().

First, make a class responsible for interpreting the input. Give it a instance of XnaConsole for handling text.

public XnaConsoleComponent Console;


Then, in the constructor, initialize the console with a SpriteFont:

Console = new XnaConsoleComponent(game, font);


Where font is your SpriteFont of choice. Next, you'll need to prompt for some input:

Console.Prompt(Prompt, Callback);


Where Prompt is the text you want to show the user, and Callback is a method you want called with the user's input. This callback needs to be a public void method that takes one string as input, such as:

public void HandleInput(string str);


Then, when you've handled the input, you may want to give a response, via Console.WriteLine():

Console.WriteLine("Response to input");


And then continue prompting for more input. That's all there is to it! If you need any more help, look at the code in PythonInterpreter.cs

Last edited Apr 5, 2008 at 9:52 PM by Shader, version 3

Comments

sylvanaar Feb 9, 2010 at 4:41 PM 
I was able to replace Python with Lua in about 15 min, great work!