March 30, 2017

TinyScript: Part I

TinyScript is my own -homemade- scripting language. It allows me to do powerful things with very little code. That's the idea behind a high-level language after all. 

Despite the fact that there are a lot of scripting languages out there, I decided to write my own demon from the ground up. Part as a whim, part as a challenge and part because is fun. 

TinyScript is very limited, as a matter of fact it is not able to do any calculations, has no local variables/functions/loop statements and lacks most of the things you would expect from a scripting language. As I said, it is very limited. Now, that I think about it, it's CRAP!

It is designed to be simple and extensible. It is easy to write, easy to maintain and performs pretty well for the kind of game I'm doing. It is mainly used to declare entities (mostly rooms and things) and for coding very specific parts of the game such as cutscenes and interactions. I also use it to define the whole game configuration which saves me from having to deploy and read a bunch of xml files.

In TinyScript, everything is a script. Each script is composed of statements. There are different kind of statements as you can see in the following class diagram:

Commands are by far the most consumed statements. Commands start with a name usually followed by a several keywords, clauses and optional arguments called flags.

The following code shows an example of what TinyScript is capable of. Let's try something with Steve Austin!

    move Steve to 145,30 #wait
    anim Steve ReachDown #wait
    pickup Steve GoldenCoin
    anim Steve ReachDown #direction:Reverse #wait
    say Steve "This coin belongs to Oscar Goldman!" #wait

The code above will move Steve to the coordinates 145,30. The #wait flag will pause the script execution until Steve reaches the expected destination. Then, he will grab something from the floor using the ReachDown animation. Once the ReachDown animation ends (because of the #wait flag) the Pickup command will put the GoldenCoin into Steve's inventory. Then, the ReachDown animation is played again, but this time in reverse direction. Finally, Steve says something about the coin.

This example gives you a good example of how TinyScript works and how useful is to make a lot of complex actions with just a few lines of tarzan-like code.

To save my time and health, I coded the TinyScript Editor. It supports syntax-highlighting and exports all scripts together into a single file.

BTW, it is about to rain around here.

- Diego

No comments:

Post a Comment