Speaking Slang

In this post we’re going to discuss one of Spycursion’s core features, an in-game programming language called Slang. By “core” I don’t necessarily mean a feature that players will interact with all the time (though I’m sure some will), but a feature that is literally a core part of the game. Spycursion contains thousands of different electronic devices — servers, laptops, phones, etc. — and, to some extent, all of them run on Slang. In fact, the Slang language was the very first code we wrote, which should give you an idea of how central it is to the game.

From a language design perspective, Slang has two main goals: Ease of use/learning, and the ability to obfuscate. The first goal is self-explanatory — it should be beginner-friendly. Here’s a simple program:

name = sys.args[ 0 ]
sys.print( 'Hello, ' name '!' )

As you might be able to guess, this program simply takes one argument, a name, and prints out a hello message. You might run this on the command line with “./hello Scott” and the program would print “Hello, Scott!” The code could even be shortened to one line instead of two:

sys.print( 'Hello, ' sys.args[ 0 ] '!' )

We hope that Slang’s syntax is easy to pick up, even for players who have never written code before. But experienced programmers will want to do a lot more than say hello to themselves, which brings us to Slang’s second design goal…

coin_flip() = sys.rand( 1 )
fun heads_or_tails ( )
    if ( coin_flip() == 0 )
        sys.print( 'Heads' )
        sys.print( 'Tails' )
i = 0
while ( i < 10 )
    i = i + 1

You might think that the above code snippet is the equivalent of flipping a coin ten times… but you would be wrong! Its practical result is to flip a coin once and print that same result ten times. That’s because in this example coin_flip() is a variable, not a function.

There are plenty more nasty clever obfuscation tricks you can do with Slang. Virtually any string can be used as a symbol name, and symbols are delimited only by white space. Using the above example again, this means that i<10 would have a very different meaning from i < 10.

Why does this obfuscation matter? Remember that Spycursion is meant to be a game of… well, spies. Spies sometimes use Trojan horses — gifts, ostensibly well-meant, with a hidden nefarious purpose. And what better Trojan horse, in the digital age, than some piece of open-source software? “It’s safe, I promise! And you have the source, so you can even review the code yourself!”

Slang is still evolving, and will likely continue to evolve even after Spycursion is released. But for now, we’d love to have your feedback. How are we doing on our design goals of ease-of-learning and obfuscation? Beginners: Did this post make sense to you? Are you excited to learn more about Slang and/or Spycursion? Non-beginners: What would you like to see from Slang? Please get in touch!