Preliminary Hotspots

Add comment!

April 18th, 2009

One of the technologies we've been focusing on recently is game scripting. As part of this effort, I've been working on hotspots. Hotspots allow us to assign a physical location to scripts. We will be using them to initiate dialogues, trigger special effects, incite AI reactions, and much more. And, of course, they will be fully moddable. Here's how they work:

We have Google's V8 javacript engine running in the background. This allows us to execute javascript scripts whenever we want. We keep these scripts running in a persistent context, so functions and variables defined in one script can be referred to in others. Previously, users could write and run scripts only in the console. Now, hotspots can also execute scripts. In the following video, I create two hotspots, one to initiate a "woozy" camera effect and a second to end it (the actual scripts are loaded in a file chooser offscreen). John once again owned the voiceover.

Click here to watch in HD!

Press the triangle button for captions (download transcript)

These scripts have the full power of javascript at hand. But they must also interface with the engine itself. To do this, we explicitly expose certain engine functions to the javascript interpreter. For example, when the interpreter comes across "Camera.setFOV(90)" it knows to call back into the C++ engine, executing "Camera::Instance()->setFOV(90)" in engine.

Hotspots aren't the only entities that can call scripts. At the start of each level, a "level script" is executed. The level script serves to setup parameters, and it's a convenient place to define functions for later use. Here's the code for the level script in the video:

level script from video

With this level script in place, the first hotspot was just linked to a script that calls woozy.start() and the second was linked to woozy.stop().

Right now, the scripts can access various camera, graphics, and network controls. Soon we will expose much more (e.g. object creation, movement and transformation controls, rabbot spawning, etc). Hopefully it will be flexible enough that people can make all sorts of random mini-games.

Do you guys have any suggestions for how hotspots and scripting should be handled?