Jump to content

  • Log In with Google      Sign In   
  • Create Account





Every game needs a console...

Posted by Aardvajk, 01 May 2014 · 460 views

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

Attached Image

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 Posted Image




That $ reminds me of Perl (shudder...)...

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

October 2014 »

S M T W T F S
   1234
567891011
12131415161718
19202122232425
26272829 30 31 

Recent Entries

Recent Comments

Recent Entries

Recent Comments

PARTNERS