World’s First Sandbox Script “Game”



Yes, it is spaghetti code.  It doesn’t even make use of my new <call>, <return> or <end> commands.

The nice thing about a scripting language built on top of XML is that the interpreter is super easy to write.  I can use FirstChild and NextSibling much of the time for navigating to the next statement.

I wound up needing a stack to keep track of which block I was in (for <if>/<while>).  As it turns out, <if> and <while> wind up being essentially the same  code-wise.  The only difference is that the node pushed to the block stack is the NextSibling in <if>, and the same node in <while>.

At this point, I have 9 total “commands”, but several of them, <if>, <while>, and <set> are rather complex.  The engine can deal with both text variables and number variables (stored in C#’s decimal type).  In fact, a number variable and a text variable can have the same name, as they are stored in different dictionaries, and escaped differently in text output.  I suppose a third “namespace” would be labels, which can again have duplication.

There are no reserved words.  There are no limitations on the names for things, other than a general prohibition on using # and $ in variable names unless you know the side effects of using them.

So, what is this good for?

At the moment, not much.  Yes, it can run a script file, but that’s about it.  It does text input and output.

However, with a small amount of work (mainly making certain methods visible), an application could conceivably load a script, set some text and number variables, run the script, and then examine some text and number variables.

For a slightly greater amount of work, it could have hooks for input/output and setting variables.

Or, if I never find a use for it, at least I can say I’ve made a general purpose scripting language.


The World’s First Sandbox Script

I have implemented <write>, <read>, <set> and <if> (at least in relation to the text type). <goto> and <label> also are implemented and work, but are not shown in the example.

<write new-line=””>Type in a word.</write>
<read text-name=”first word”/>
<write new-line=””>Type in another word.</write>
<read text-name=”second word”/>
<if text-name=”first word” comparison=”equals” compare-to=”$second word$”>
<write new-line=””>The strings are equal.</write>
<if text-name=”first word” comparison=”less” compare-to=”$second word$”>
<write new-line=””>$first word$ comes before $second word$.</write>
<if text-name=”first word” comparison=”greater” compare-to=”$second word$”>
<write new-line=””>$second word$ comes before $first word$.</write>
<read text-name=”dummy”/>


Sandbox Script

I really enjoyed making the IF Player and designing the script that went along with it.

In fact, I liked it so much that I decided to make another XML based scripting language, but this one more general purpose.

Because I like to.

This one, however, will also have the ability to store numbers and strings, as well as boolean flags.

Also decided on a simple scheme to output the values or number variables and strings.

String variables will be escaped between two $, like $name$.

Number variables will be escaped between two #, like #value#.

Flag, I decided, did not need to be able to be escaped.

When output or any sort of string is unescaped, it first unescapes strings, then numbers.

The escaping does not nest, to keep it simple.

Decided also to include a number of different comparisons for <if>.

Also decided to put in a <while> loop.

Also decided to put in <goto> and <label>, and <gosub> and <return>.

Anyway, I think it is fun.