• entries
    743
  • comments
    1924
  • views
    577733

Every game needs a console...

Sign in to follow this  
Followers 0
Aardvajk

832 views

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

game.jpg

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

5
Sign in to follow this  
Followers 0


2 Comments


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

1

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