Scripting

From OpenMW

Revision as of 19:04, 3 March 2009 by 127.0.0.1 (Talk)
Jump to: navigation, search

This page will be updated continuously as scripting in OpenMW progresses further.

OpenMW uses Monster script as a scripting language. Monster is a new language made specifically for game development, which originally started as spin-off project from OpenMW itself. It's currently being actively developed alongside OpenMW.

We plan to create most or all of the game rules in Monster script in the future. Only a small portion of the scripts have been written yet though, and this page is a (very sparse) documentation of the current scripts.

You'll find all the Monster scripts in the mscripts/ directory in the OpenMW download, in files with the .mn extension.

Contents

Game settings (GMST)

The class 'GMST' is defined in mscripts/gmst.mn. It contains all the game setting variables from Morrowind, Tribunal and Bloodmoon as member variables. The class is a singleton, meaning that one global instance is created automatically and can be accessed through the class name.

For example, you can access the fTravelMult setting from any script like this:

 writeln("fTravelMult has the value: ", GMST.fTravelMult); // print the current value to screen
 GMST.fTravelMult *= 2;                                    // set the new value to twice the old value

The variables of the GMST class are loaded with the actual GMST values (from ESMs and plugins) at startup by the back-end system.

Config

The file mscripts/config.mn contains various config options (like mouse sensitivity and sound volume). Not much here yet, but it will be extended later to control everything from key bindings to screen resolution.

Game objects

All the objects loaded from ESMs and ESPs (weapons, books, NPCs, static meshes and so on) are loaded into each their own Monster object. The classes for these can be found in mscripts/gameobjects/.

For example, the 'Door' class is found in mscripts/gameobjects/door.mn. Each door in a loaded cell has a separate instance (object) of this class. At the moment these scripts have no functionality, they only hold data. The interaction between the various objects will be coded later.

Music jukebox

The background music is controlled by the scripts in mscripts/sound/. The jukebox is pretty simple but it supports playlists, randomization and fading. There's two jukeboxes, one for battle-music and one for 'normal' music. When switching modes, one fades out while the other fades in.

The jukebox.mn script is a good example of how to use the built-in state mechanisms in Monster. A jukebox is always in one of four states: playing, not playing (empty state), fading in or fading out. A good jukebox has to be able to safely change between the states at any time, and when fading it also has to keep updating the volume at regular intervals. Monster's state and virtual thread system makes all this completely automatic.

GUI

We're currently experimenting with implementing the GUI in Monster. This isn't done yet. Most of the GUI (except the FPS ticker, see below) is still hard-coded.

FPS counter

The FPS counter in the upper right corner is created and controlled by the script mscripts/fpsticker.mn, using an early version of the GUI module.

Relation to Morrowind scripts

There's no real relation between the in-game MW scripts used in ESMs and mods and Monster. OpenMW will run both scripting languages simultaneously (when it's done) - but it's likely that most of the MW script backend (the actual functions) will themselves be implemented in Monster. It's also possible that we'll convert the MW scripts to Monster byte code at runtime.

Personal tools