Code Highlighting for Kirikiri in Sublime Text (and more)

* This post doesn’t have a lot of merit for non technical users, sorry. 🙁

Since I’ve been working a lot with the Krkr engine (Pronounced Kirikiri), I’ve been working a lot on building a useful work environment for writing scripts up, which I figured I’d share in case there’s someone out there who could make use of it.

Code Highlighting

Sublime Text is presently my favorite text editor.  It’s lightweight, easy to use, and can be made to do just about anything.  Before using sublime for krkr scripts I used to use KKDE, a dev environment specifically for krkr games.  I found it a little hard to work with though (it keeps converting unicode scripts to SJIS, which crash on English Windows), and wanted to be able to use Sublime for my editing.

Code highlighting is probably the most important thing when it comes to making code readable, so I’ve created my own package for Sublime Text.  It handles both flavors of scripts, the KAG Scripts (.ks) and TVP Java Script (.tjs) files.

The TJS script highlighting actually uses a modified version of the Javascript highlighting system.  I’ve added in a lot of krkr specific keywords and took out ones that aren’t used in TJS.  For KS scripts, the highlighting was done from scratch and  handles standard block type commands, @ type commands, and will even allow nested TJS code in [iscript][endscript] blocks.

KS script highlighting.

TJS script highlighting.

The only limitation I’ve run into so far is that it won’t do all the tag types in KAGEX type scripts, or for games that use a custom conductor (such as Alcot’s titles). Still, it’s great for regular krkr scripts.

Grab the sublime package here.

 

Build System

This is something I’ve finally got going in sublime, although I guess it’s not really a build system since krkr doesn’t ‘build’ at all. What it does though is allow you to jump directly from the editor into the script you’re currently working on, which is a big time saver.

What I’ve done is I’ve set up sublime text to launch launchkrkr.exe in the root project folder (so you have to have a project created and have krkr be in the root path) when you try to build a .ks or .tjs file. Launchkrkr.exe simply closes the game window in case you left it open from last launch (which I always end up doing), and and launches it in debug with the script name and path. Note that script name and path are only included for .ks scripts, if you run from a .tjs file it will just open your game normally. Also, the game exe will need to be called krkr.exe for it to run.

Just launching the game with the parameters won’t do anything though, you’ll have to actually make use of them. In startup.tjs, I’ve added the following code to handle those parameters. It’s a mess (globals in kirikiri are messy though), but it takes the passed arguments, and assigns the global variables launchscript, usescript, and usescriptdir. It also checks to see if the script is located in the ‘scenario’ folder, as scripts I don’t want to be directly executed I’ve put into the ‘scripts’ folder instead.

//Allows startup to any script directly from the editor
var launchscript = false;
var usescript = '';
var usescriptdir = '';

if(System.getArgument('-debug') == 'yes')
{
	usescript = System.getArgument('-usescript');
	usescriptdir = System.getArgument('-scriptdir');
	if(typeof(usescript) != void && usescript != '' && usescriptdir != '')
	{
		//We want to ensure we are only jumping to scripts in the 'scenario' folder.
		var temp = usescriptdir.split("\\");
		if(temp.length > 1)
		{
			temp = temp[temp.length - 1];
			if(temp == 'scenario')
				launchscript = true;
		}
		invalidate temp;
	}
}

And then somewhere after all your macros and plugins and stuff are loaded, probably in first.ks, you stick in something like this:

[if exp="global.launchscript == true"]
	[call storage="&global.usescript"]
[endif]

Once the script finishes running, it’ll continue to your main menu or wherever it would normally go when you launched.  Easy! The build stuff is already in the sublime package, just grab the launchkrkr.exe below. I’ve included the source too if you want to edit it, it’s super short.

I can get away with this now that the game’s announced. Hopefully.

Grab launchkrkr.exe here.

 

3 Responses to Code Highlighting for Kirikiri in Sublime Text (and more)

  1. Saidai says:

    Will have a play with these tomorrow after class.

  2. MrTimscampi says:

    Hi, I’d be interested in that launchkrkr.exe but it asks for a password… 🙂
    The Sublime-Package file is fine though. :p

  3. Scorp says:

    Was fiddling with these tools for some time, thx for this cool idea about using Sublime 🙂 Your colorer works fine, apart a small thing:

    if there is a thing like [jump target=”*S0-01_01″] regexp fail to match this and eats all, including ” and more and more. I do not know why, seems Sublime 2 have a bug or like that, so I replaced all \\w-_ with \\w\\-_ and it seems started working as it should.

    Then, I tried to get use of launchkr, it works fine, just code you told [if exp=”global.launchscript == true”] returns false, if you have file name like r001.ks, this is not PHP 🙂 So replaced with [if exp=”global.launchscript != ””] and works fine now.

Leave a Reply

Your email address will not be published. Required fields are marked *