Doki Doki Games Development Blog
Implementing a scripting language in a scripting language…

I’m planning on implementing a scripting language in Unity. Insane right? Unity already comes with effectively three scripting languages - doesn’t it?

Yes. Yes it does. But what I’m planning on implementing is something far more high level than the C# and friends that power unity.

To get some idea of what I am talking about I need to go historic.

Back in 1993 I joined a UK Game Dev called Argonaut Software. They were famous at the time for pushing 3D games with the original Starglider and Starglider 2.

Soon after Argonaut started working with Nintendo on something special. That something special was a game called Starfox and the Super FX.

This relationship meant that some of the programming/tech guys got to go out to Kyoto and work with Nintendo.

This was a time when Japan was way ahead of the rest of the world in terms of game design. For years they had ‘Planners’, whereas in the UK the industry grew up on games made by a coder and sometimes an artist. For the Japanese, having planners on their team meant that they had members of the team that were purely focused on what the game should be and how the game should play.

Dylan Cuthbert was one of the programmers on the original Starfox and was also finishing off Starfox 2 at Argonaut’s London office. It was here that I first saw the scripting language that they used for those games.

It was one step up from Assembler. From what I remember it was a series of three letter acronym and values that ran in sequence to control the flow of the levels and the individual objects. I can’t remember if it was compiled but since it was so close to Assembler it probably went straight into some kind of byte code interpretor.

Being programming savvy, but not what I’d consider a real game programmer, the scripting language (or Strategy Language I think it was called) appealed to me because I could have direct input on the game without having to have written the engine.

For the next few projects we implemented increasing sophisticated ‘Strat Languages’. Creature Shock DX (apologies to the 12 people that played this) took some of the concepts of Starfox Strat Language and started to bring them into a more high level language. This all culminated with the development of Croc for the PS1.

Croc had a pretty sophisticated Strat Language that powered every object in the game. For the first time everything from ‘Croc’, right down to the Crystals he collected was written in ASL (Argonaut Strat Language). It was a high level language that was very readable and very designer friendly.

ASL (and the ‘Croc engine’) powered a bunch of games at Argonaut from Croc 2 to the Disney games we did and ASL went on to integrated into the PS2/Xbox engine that Argonaut. By the time Argonaut Software came to an end a very sophisticated version of ASL was being used in both Catwoman and I-Ninja.

A few years later I was working on a FF7:Dirge of Cerberus - Lost Episode for Square Enix over at Ideaworks3D in London.

Being their first ‘non-port, non-driving game’ project we didn’t have a lot of tech to build the game on. Knowing we needed a scripting language we decided to build on top of LUA. LUA was great because it meant we didn’t have to create something from scratch to deal with all the standard programming stuff like loops, variable usages etc. We also built tools on top of Maya to turn it into a level editor for the game.

A LUA/Maya combination was also used on the Clone Wars project I did over at Lucas Singapore.

This brings me to Unity. Unity is essentially a streamlined version of the tools we used on Dirge. The missing component is the inclusion of a high level scripting language, tuned to dealing with game play. Simply put, a game script deals with fundamental things such as:

  • Setting game states
  • Setting trigger events
  • Responding to input
  • Moving characters to relative positions
  • Moving characters along paths
  • Setting up and controlling different types of collisions
  • Setting camera positions
  • Spawning Objects
  • Handling death

etc.

Here’s what a script that sets up a small cutscene at the beginning of a level might look like:

function introCutScene()

 setCutSceneMode(true)

 wait(2)

 setCamera("CameraAnim_Intro")
 cameraSetTarget("CameraAnim_Intro", player)

 textBoxMessage("Come with me if you want to live...")
 wait(60)
 textBoxMessage("Not likely Mister")
 wait(60)

 setCutSceneMode(false)
 playAnim(player, "Idlenoaim", true)


 setPlayerControl(true)

}

A script that controls a game level looks a lot like an extended version of this script. Simple put, it’ll wait for a player to trigger something in the scene and react with a small amount of script. This could be a collision box trigger in the scene or an event like killing 100 enemies.

A good example of a somewhat arcane scripting language is Pokescript, which has allowed Pokemon hackers to experiment with creating their own Pokemon games.

History lesson over, I still need to answer why I’d want to build something like this in Unity?

For me there’s three sides to game programming. The first is the engine. This is the code that deals with rendering the scene, lights, textures, sound, input, IO etc. That’s Unity.

Second is the game code. That’s code that uses the engine to make game specific stuff happen. For example any special physics you need, or implementing code to deal with a context sensitive input or path finding for example. Basically the code that is the foundation of your game. Unity also does a great job in providing the tools to make the game code.

Finally you have the code that delivers the game experience. The enemy AI, the scripted events, that platform that simply moves up and down. Now - Unity does all this, but I feel more comfortable with a level of abstraction.

See for me, even though these three elements all work together I always see them as different boxes. If the game engine is working - great, don’t mess with it. If the game code is working - wonderful, leave it alone.

With those two in place you are free to input into these fully functional boxes with your game scripts. Here you’re directly working with the scene and writing bits of code to make it come alive. That’s where the designer in me is most happy.

The great thing about Unity is that I don’t have to be an engine coder. I only have to be a bit of a game coder. And with a simplified scripting language built on top - I can be all designer and have a reusable game engine that is focused on making fun.

To be clear - I’m not talking about anything more than a series of simple functions written in C# that are focuses purely on scripting events in the scene. It’ll simply be a reusable library that will allow me to be a designer again - not a programmer.

I’ll let you know how I get on.

The Best Free Tools for Indie Game Devs

Free software is everywhere. This is a mana from heaven to a developer on a shoe-string budget (or no budget). In this article I’m going to quickly run down some of the software I use in my personal game development, and some I use in my day job as a Pro Games Designer, to help get ideas together and on to the screen.

Design Tools:

Even though I’m a career games designer, when I’m playing around with my personal projects I very rarely sit down and write a design. THIS IS BAD. You really do need to have some kind of plan or you’ll never finish, and remember - finishing is everything! 

My excuse is that I spend my working life stuck in MS Word doing games planning and systems design so when I want to make something for fun, why would I want to sit down and spend all my time in a Word Processor. 

The hack your way through it without a plan is fine if you’re making a game like Doki Doki Bloki (which is just a riff off of Picross) but if you are planning something more original you really need to get your game down on paper first. 

Luckily there are tools out there that can make the process fun, iterative, and save you a lot of time when developing your game. Best of all, they are free.

XMind (http://www.xmind.net/)

XMind is a Mind Mapper. Mind Mappers are great for breaking down an idea into important elements or tasks. This could be designing the structure for your MySQL databases, or how your inventory system works, and definitely the structure and flow of your game. 

If you’re solo developer or part of a small team, a mind map may be all the documentation you need to keep you on your path. I’ve only just started to use Mind Mapping software but I feel like a bit of an idiot for not using them sooner. 

They are very useful for putting together the skeleton of your thoughts. From there it’s easier to write out in detail or, for smaller projects, just go straight into development. 

Feng Office (http://www.fengoffice.com/web/)

Feng Office is an online project management tool. Sounds scary? Not at all. When you are an Indie developer you have the luxury of flexible developement. I’m not advocating you go crazy on project management and plan every single task. I am recommending that you have a central resource for organizing your information. 

With Feng Office a small team can work in geographically diverse locations and have a central resource for tracking their game. For me, I simply use it as an online notebook that allows me to quickly add a task or make some notes or store a web link where ever I am. 

You can write your design documentation here, split up your tasks, set deadlines (Pro to Indie tip: deadlines are always important) etc. 

If you’re using contractors you can use the tool as a tool to keep track of work coming in and how long things took so you can pay them for their work. 

It comes in two flavors. You can pay to have them handle your data, or you can install the software on your own server for free. Its easy to install so if you have a web sever (I use dreamhost and it’s cheap) and you want to keep on free street - just go with the install version.

Google Docs (http://docs.google.com)

If Feng Office seems like a step too far, Google offers all the tools you’ll need to get your ideas down in type without ever having to install Office or Works and your information will be available to you where ever you are in the world. 

The Google tools are not as good as the commercial packages but they do cover all the bases and are perfectly adequate for most tasks. 

Game Engines:

Unless you are supremely talented, or part of a large well funded team, or just a little insane, you’ll be wanting to use and off the shelf Game Engine. 

It wasn’t always the case. I’ve been pro for over 17 years and my latest project is the first I’ve worked on to use an off the shelf engine (Unreal). Before that we built everything from scratch - engine, editors, scripting language, the works!

With engines like Unity and UDK, anyone who wants to make a game has access to the same powerful tools that the pros use.

Unity (http://unity3d.com/)

For Indie Development, this is my tool of choice. 

It’s well structured, powerful and easy to pick up. Unity provide great tutorials and sample projects that can help you get up and running with your idea very quickly. 

Unity is not a ‘push button - make game’ solution (they don’t exist). You still have to put in the hours to learn how it all works. Doki Doki Bloki was my learning project. Make something small, learn the tool and you’ll soon be on to bigger and better things. 

Unity has an amazing community that has saved me on many occations when I hit problems, and the team at Unity are pretty active in offering advice and helping out with problems.

Unity allows publishing on PC, Mac, Web Browser, iPhone, Android, Wii, PS3, Xbox 360. 

This gives you the potential to get your game out to a very wide audience. And don’t underestimate the power of the Web Browser in the future of videogames :)

So - good people, good tool, good community = great product, and it’s free. There is a paid Pro version, but you can still make a great game on the free version with no restrictions. 

UDK (http://www.udk.com/)

I haven’t used UDK, but use Unreal 3 on the current project I’m working on. Unreal is a supremely powerful tool for making Pro games. 

So why do I recommend Unity? 

If you are a Pro developer that has used Unreal in the past and want to release a product for the PC (possibly consoles) that is an installed game then UDK is probably the tool for you. 

If not - check out Unity first as it has a much easier learning curve. Also, be aware that UDK has some ‘interesting’ publishing restrictions you need to be aware.

Source Editing:

When you’re developing your game, you need to write code. Unity used to come with it’s own basic text editor but for serous work you need to use an IDE. Luckily there are some great, free choices out there. 

Microsoft has free editions of their Visual Studio series, but I’m going to talk about an alternative that is now the de facto editor for Unity 3.

MonoDevelop (http://monodevelop.com/)

I’ve been using MonoDevelop for around a year now. Prior to that it was a little unstable, but then seemingly overnight it because an amazingly good tool for working with Unity. 

As of Unity 3, MonoDevelop has become the standard editor for Unity. It’s super easy to setup, has wonderful line completion, meaning I don’t have to remember every single Unity function name, and as of Unity 3 you can do code level debugging. 

I’m not sure how well MonoDevelop works with Java and Boo because I just use C#, but if Unity as packing MonoDevelop with version 3 I’m pretty sure it’s all working just fine.

3D Apps:

3D can be scary. If you’re new to making games, there’s enough to handle with just learning the Engine let alone creating art assets for your project. If you’re lucky, you’ll have a friend or co-developer handling your art. However, never fear. There are free tools out there that are easy to use and can help you get your game up and running very quickly.

SketchUp (http://sketchup.google.com/)

SketchUp is a free tool that is now owned by Google. Originally designed for Architects, I’ve been using SketchUp for close to seven years now for developing game concepts, prototyping level ideas, and even simple game assets. 

It’s the simplest 3D tool out there and there are lots of training videos on YouTube to get you started. 

The free version exports to a format called Collada. This is an open format for exchanging 3D data between programs. This is useful because you’ll want to be getting your model out of SketchUp and into Unity. 

Hmmmm… okay. So this is where you are going to hit a problem. Unity doesn’t like the Collada data that SketchUp export. I’m not sure why, but help is at hand. 

Greg at CaffeinatedGames has made a simple app to convert the SketchUp Collada files to a format called FBX which Unity loves. 

You can buy the convertor here: http://www.caffeinatedbits.com/ for as little as $1 - but if you have more to spend, you should give a little more. 

Just a word of warning. SketchUp models can be a little messy. It’s easy to forget which way your normals are facing and the models often have way more polygons than are needed. You also can’t UV texture models in SketchUp. But for prototyping and getting objects into your game quickly for test - SketchUp is your friend!

Blender (http://www.blender.org/)

Blender is an open source 3D tool that I simply HATE! HATE HATE HATE!!

Every time I check it out - I remember why I hate it! Needlessly complicated. Terrible Interface. Workflow from another planet.

So why am I including it in my list. Well, yes it’s free - but more importantly the new beta has a vastly improved interface. 

This has always been a big problem with Blender in the past. I know Blender users are going to hate me for saying it, but if I can’t create a cube and extrude a face within one minute of looking at a new 3D app, it gets deleted. 

Blender 2.5.3’s default scene already has a cube so it’s cheating a little - but I found the new interface pretty easy to pick up

This version of Blender is still installed on my Mac and I intend to dig a little deeper with it to see if it’s something I can use. I worry that because of the new interface all the learning resources will be out date, but the bold changes are essential for Blender to stop being an industry joke and start being considered a professional tool. 

You know, I really shouldn’t hate. It’s feature rich, and free.  It’s the only real no budget alternative are the big boys like Maya, XSI, and Max. The Blender team should be applauded for addressing the interface and I think it’s going to open up the tool to a much wider audience.

If you’re Indie, broke, and want to be legit (yes you do!) then Blender is a no brainer for creating your assets. 

Animeeple (http://www.animeeple.com/)

This is a tool I haven’t really used but it sitting on my Mac just waiting for the day I need to do some character animation. I’m the kind of dev that doesn’t mind switching between different applications if that app is well designed and focused on a single task. 

Animeeple is just that. It’s focus is to take your existing rigged character and give you the tools to quickly and simply animate it. The software also allows Mocap data to be applied to your character if you don’t have the skills, the staff or the time to animate your own character.

An alternative to Animeeple is Mixamo (http://www.mixamo.com/). Their service allows you to upload your characters and try out their mocap data on your rig. If you like what you see you can buy the motion data and use it in your game. There’s lots of support for Unity and the latest version allows you to preview the motions on a meshed character. This is something I feel that is essential and was missing from their pipeline until recently.

2D Art:

Not all games need 3D art. And even 3D art needs textures. Again, free software comes to our rescue.

InkScape (http://www.inkscape.org/)

InkScape is my tool of choice for vector 2D work. I could never get my head around Illustrator. InkScape I just immediately picked up. I make textures in it but also use it a lot for design documentation when I need to create diagrams or annotate a bitmap. 

It’s a little buggy on 64-Bit Windows but on the Mac I’ve never had any problems. 

Gimp (http://www.gimp.org/)

I’m not a huge fan of Gimp, but for what I need it’s free and does the job. I mainly use it as an image editor, not an art tool. It’s interface is not as refined as Photoshop but you all know how much Photoshop costs! For that financial pain, I’ll take a little interface pain.

Audio:

I can’t find any good, free audio apps. Yes, there’s Audacity which you can use for basic audio editing, but there’s no free versions or alterntives of Ableton, Pro Tools, Logic etc.

However, do not fear! There is a cheap and powerful tool out there that is gaining many fans.

Reaper (http://www.reaper.fm/)

Reaper is not free, but if you’re Indie you can get the discounted license for $60.

I’ve not used it but I know people who have and they think it’s a great tool. Time for me to download a copy and have a play!

Added a simple iTween c# scene

To help get iTween up and running in your c# system I’ve uploaded a very simple scene. Please make sure you grab the latest version of iTween if this post looks old. Grab the scene from here.

Nic.

Using iTween JavaScript in a C# project

Bob @pixelplacement asked me to put together a short ‘How To’ on my work flow of using the iTween JavaScript version in a C# environment. I’m generally not a big fan of mixing my languages in a project, but iTween sits so well in Unity that I forget that it’s not built in!

Installing iTween

Simply drop iTween.js into a ‘Plugins’ folder in the root of your ‘Assets’ folder and you are good to go.

If it Moves, iTween it!

I use iTween for a lot of things in my project, but a basic rule is if it Moves, Beeps or Mouse Overs - iTween it.

Calling iTween in C#

Calling iTween in C# is a little different to using JavaScript, mainly because of how C# in Unity handles hash tables. Luckily I was used to setting up hash tables thanks to using the C# version of ‘Ani.Move’ so using iTween was very familiar.

Here’s how to use iTween for a simple move in C#:

------------------------------------------------------------

// Create a new Hashtable
Hashtable ht = new Hashtable();


// add to the hash table the parameters for the move
// see the excellent online iTween docs for the valid params
ht.Add(”x”, 10);

// tell iTween to use this gameObject and the hash table we
//created
iTween.moveTo(gameObject, ht);

------------------------------------------------------------

This example will move the game object with this script attached to it 10 units in the X direction only. So setting up the hash table is a little bit more work than JavaScript but the results are well worth it.

More complex iTweening

The more I’ve used iTween the more I am amazed at how the simplest application of it can have dramatic effects. The was most obvious was when appled iTween to the basic camera code we had in our current game.

The camera in our project is fixed to our player character and only allows movement in the X and Z. The player can push the camera closer or further away but no rotation. Before using iTween this camera matched our player movements exactly. This made the world feel like it was moving under our player instead of the player moving through the world.

I talked to Bob about allowing the moveTo and rotateTo functions to take Vector3 position, not just fixed world units. A day later iTween was updated with moveToUpdate and lookToUpdate. Applying these functions to our camera code suddenly made the game feel like we had spent weeks working on the camera easing. This is the code in the camera Update loop of our game:

------------------------------------------------------------

// grab the position of the camera
tempVec3 = transform.position;

// Camera has a reference to the player. I grab the X,Y,Z
// then add to the Y my camera height and the Z my camera
// Depth. This gives us our position for the camera.
tempVec3 = new Vector3 (playerObj.transform.position.x, playerObj.transform.position.y + camHeight, playerObj.transform.position.z + camDepth);


// Now we tell our camera to move to the new position
//using iTween
Hashtable ht = new Hashtable ();

// This is the position of the camera
ht.Add ("position", tempVec3);

// This is how quickly we want to move the camera to the
// new position. This short time allow the camera to
// lag behind the player character
ht.Add ("time", 0.2);

iTween.moveToUpdate (gameObject, ht);

// Now we give the camera a little look to rotation. Let’s
// grab the player position
tempVec3 = playerObj.transform.position;

// Create a new hash table
Hashtable ht2 = new Hashtable ();

// Set the look to target as the player
ht2.Add ("target", tempVec3);

// and set the look to speed. This is also slow so we get a
// nice camera lag
ht2.Add ("lookSpeed", 4);

iTween.lookToUpdate (gameObject, ht2);

------------------------------------------------------------

Simple. Suddenly our camera feels like a really polished game camera.

Punch it in the face!

Another set of wonderful features are the ‘punch’ functions. Our game is cute. Everything bounces. When you mouse over an object in our world that you can interact with iTween makes it spring to attention. This is achieved as follows:

------------------------------------------------------------

void OnMouseEnter () {
// I store the reset scale in the Awake function so it can
// be reset here. This stops the object from shrinking or
// expanding by quickly mousing over
transform.localScale = myScale;

// Create a new hash table
Hashtable ht = new Hashtable ();

// we want the game object to bounce scale in all axis
ht.Add ("x", 0.3);
ht.Add ("y", 0.3);
ht.Add ("z", 0.3);

// and bounce for 1 second
ht.Add ("time", 1);

// send all that to punchScale and we are good to go!
iTween.punchScale (gameObject, ht);

// I use a messaging system. This sends a message
// to our sound controller which also uses iTween!!!!
Messenger.Broadcast ("playSFX", "overSFX");
}

------------------------------------------------------------

Using iTween for Sound Effects

iTween can also handle sound. I have a single sound controller in the game that handles all the none positional sound effects. I then use a messaging system to communicate with it.

Here’s how iTween is used in the sound controller:

------------------------------------------------------------

Hashtable ht = new Hashtable();

// tell iTween which AudioClip to use
ht.Add("clip", sound);

// set the volume
ht.Add("volume", 1.5f);

// tell iTween to play the sound
iTween.stab(gameObject, ht);

So why use iTween for audio? Well - iTween is smart. It will automatically assign a new audio clip to the game object every time it’s called. This means that you don’t get the audio cutting itself out when you tell the sound controller to play a new sound. iTween also cleans up after itself once the sound has played.

Using ‘onComplete’

Another great feature of iTween is its ability to call back once it has finished an operation. At first I found it a little hit and miss until I realised you need to use IEnumerator for the callback function.

In our game you can delete objects. I use iTween to scale down the object when it’s deleted and then call a function to remove it from the scene once it’s finished. It looks a little something like this:

------------------------------------------------------------

void handleObject() {

// some checks to make sure we don’t delete
// multiple times
if (overObject && !deletingObject) {

// not iTween - I’m sending a message to turn off all
// input
Messenger.Broadcast("noControl");
overObject = false;
deletingObject = true;

// This is a simple scale down using iTween
Hashtable ht = new Hashtable();
ht.Add("x", 0);
ht.Add("y", 0);
ht.Add("z", 0);

// This is the clever stuff. Once it’s finished it calls
// the function “finishOff”
ht.Add("onComplete", "finishOff");

ht.Add("time", 1.5);
iTween.scaleTo(gameObject, ht);

Messenger.Broadcast("playSFX", "removeSFX");
}
}

// This is the code that is called once iTween is finished

IEnumerator finishOff() {

Messenger.Broadcast("playSFX", "shrinkSFX");
Destroy(gameObject);

}

------------------------------------------------------------

I hope this little introduction using iTween in C# will get you up and running using this awesome library in your own projects. It can add polish to your games that would take weeks of coding (or more in my case!!).

I’m only scratching the surface and I’m sure as development continues I’ll be using for all kinds of things. If you’ve got any questions - please drop a comment on this post.

You can also view this as a PDF HERE

Hello from Doki Doki Games

It’s been years since I blogged but I was inspired to create this blog after writing up a ‘how to’ on using iTween in a C# environment in Unity for Bob over at Pixel Placement.

The Unity community is incredibly giving and we Doki Doki Gamers also want to give! I’ll be honest – my programming level is totally intermediate (I’m a Games Designer by trade), but that’s a good thing. If you’re starting out with Unity you will probably face all the same questions I faced and hopefully I’ll be able to help you out!

Unity empowers anyone with the passion to create a game to… erm… create a game. I’ve used many different game engines in my career, and helped design a fair share of internal engines that have gone on to have multi-million sellers built on them and Unity is the best off the shelf solution I have ever used. In terms of power/cost/ease – nothing comes close.

So if you’re new to Unity, confused if you should use Unity, or simply interested in some of the things going into our new game – welcome to the Doki Doki Games Dev Blog. We hope you find something useful here!