This is a tool I’ve made to develop Tanuki Tail, but decided to release because I’m so awesome and helpful.
BaSS is a script language toolkit I’ve made (and still work on from time to time). It lets you create script files that use a script language of your invention. For example, if you are making an RPG you may want to create scripts for your NPC events. For example, when you talk to someone make him face you, load a text, print the text, maybe give or take an item, etc. It also has other uses, like event animations (example: “walk two tiles up, then turn around, make the character jump…”) or anything that comes into mind. After all, the final result is an array of bytes with the meaning you gave to them.
The current toolkit consists of two tools, Luthier and Performer, both of which are command line text parsers. The toolkit comes with a manual that explains pretty much everything.
Luthier creates BaSS language files from text files. This is, the collection of commands you want to use to compile scripts with Performer. Read the manual and example to get a better idea, but, a quick one: Command number 5, named “loadtext”, which receives one parameter of length two (bytes), called textID Command number 6, named “printloadedtext”, which receives no parameters. Construct “print”, which receives one parameter of length 2 (bytes) called textID. This gets translated into “loadtext textID” and “printloadedtext”
5 loadtext 1 2 textID
6 printloadedtext 0
X print 1 2 textID // loadtext textID \ printloadedtext
These three lines would put two commands and a construct in the language:
As you can see, this also implements constructs, which are something similar to macros in C. A construct is translated as one of more commands with parameters (constant or parameters of the construct), which is useful for common script lines, aliases (multiple names) of a command, or, with label references, jump commands.
Presumably, loadtext would load a text reference into some buffer, printloadedtext would output it, and print would do both things.
Luthier also lets you define things like maximum script file size, coordinate types size (each script has two coordinates: bank and script, and offset as an offset in the script file), endianess of data bigger than one byte, file extension, etc.
The second tool is Performer, which is the actual script compiler. Given a text source file and a language file (created with BaSS), generates a file containing the array of bytes that represent such script. For example, with the previous commands, the script
%TARGET 0 1
would generate a script with the bytes 5 10 6 5 11 6 (also, would save it in ./scripts/0/1.), which would, presumably, output texts number 10 and number 11. Constructs get translated into the commands they mean
It is possible to #define things with a %DEFINE directive.
It is also possible to insert labels. Labels are references to a script bank-script-offset coordinate, and can be added in a script to create a reference to that exact point of the script. You can create constructs that accept Label or Extlabel types, and then, when compiling, Performer looks up that label. If it’s a Label, it looks in the current script. If it is an Extlabel, it looks in a labels file, where all the labels from compiled scripts are stored.
Once you have your language defined, you have to implement the commands into your game. The logical way to do this is sequentially, with jumps of needed, by creating a while loop that reads the whole array byte by byte and running each command depending on the byte read (with a switch statement, for example).
This is a beta. There is a lot to improve and a lot of code to clean. Once the code is cleaned enough so it doesn’t embarrass me, I’ll release version 1, which will be open source.
Feedback is welcomed, being it praise, bug reports, comments, questions…
Download it right now.