Jump to content
  • Advertisement
  • entries
  • comments
  • views

Every game needs a console...

Sign in to follow this  


Every game needs a console, and here is mine...


Never one for keeping things simple, I decided that I wanted to unify the console inputs and file configuration system by inventing a new language called XCS (extensible configuration script). I've built it all as a static lib as it isn't project specific.

Syntax-wise, everything is either an assignment or a command:a = 23;b = 10.0;c = "Hello World";d = false;echo 12 34
Anything not followed by an '=' is passed back to the host application as a command, along with its parameters. The host application can then implement the command however it chooses.

The host application can also easily query for the value of any assigned variable, which are returned in an Xcs::Variant type which can be converted to and from int, string, float, bool and list. The list is a std::vector of Xcs::Variants so you can create nested structures. Lists are defined in the script using braces:a = { 1 2 3 };b = { lists are { recursive as } well };
Any variable can be referenced in the script by prefixing its name with a '$' character:a = 39;echo $a;
Finally, comma is a string concatenation operator, so any values separated by a comma are turned into a single string before it is returned, although variable substitution still takes place:a = 100;b = "One hundred is ", $a, " in digit form";
As far as the host application is concerned, b contains "One hundred is 100 in digit form" here.

So this works well for a configuration file for the game, where you can define any variables. It also works as a command-line language for use in the console shown above. The semi-colon is optional if the statement is the last one in the input, so in the console where each line is a separate script, it is just like typing command line commands.

It also means we unify options set in configuration files and options then available from the console, which will be useful for development later on.

Anyway, that's today's post. Time between my posts seems to vary between hours and years smile.png
Sign in to follow this  


Recommended Comments

I was almost about to start putting in conditionals and functions, then I had to kick myself back to the game :)

Share this comment

Link to comment

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
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!