Upcoming Events
Unite 2010
11/10 - 11/12 @ Montréal, Canada

GDC China
12/5 - 12/7 @ Shanghai, China

Asia Game Show 2010
12/24 - 12/27  

GDC 2011
2/28 - 3/4 @ San Francisco, CA

More events...
Quick Stats
115 people currently visiting GDNet.
2406 articles in the reference section.

Help us fight cancer!
Join SETI Team GDNet!
Link to us Events 4 Gamers
Intel sponsors gamedev.net search:

Introduction to GameMonkey Script Part 1
Language Introduction


Introduction

This article will introduce you to the GameMonkey Script (abbreviated to GM Script or simply GM) language and API and how it can be used in your own games. It begins with a short introduction to the language and how it compares to Lua, the most similar language to GM Script and also a popular choice in game development. The article will then show you the basic features of the script language itself and, in the second part, teach you how to bind the virtual machine with your game applications. This article does not intend to be a comprehensive tutorial on using GameMonkey Script, nor will it cover the advanced topics and techniques that can be employed when scripting, however it will be enough to whet your appetite for GM Script and provide you with enough information to explore the language on your own. You can follow along with the examples in the code by experimenting with the gme.exe program that ships with standard GameMonkey distributions and running the example scripts that are supplied with this article.

Prerequisites

In order to get the most of this article and indeed GameMonkey script, it is assumed that:

  1. You have a working C++ compiler environment (an IDE or command-line, it doesn't matter)
  2. You are able to program to an average level in C++
  3. You are able to understand languages with a similar syntax to C/C++
  4. You have an interest or requirement in embedding scripting languages

What Is GameMonkey Script?

Scripting in games has long been an important technique for developers to employ. Scripting allows you to separate your game logic from your engine code and gives you the ability to tweak your content without time-consuming rebuilds of the entire engine. Some games, for example Unreal, have vastly complicated scripting environments in place which allow you to create graphical effects and perform almost every action imaginable in your game. In the past it was popular for game developers to 'roll their own' scripting language that was tied directly into their game systems, however language parsing and virtual machine design is a complex subject, meaning that many developers are now choosing to use a third party scripting language.

Influenced by the popular embedded scripting language Lua, Matthew Riek and Greg Douglas set about creating their very own language for a game project whilst employment at Auran Software; and thus GameMonkey Script was born. Created specifically for game scripting, GM Script is written with speed and simplicity in mind. The original version of GM Script has been used in several commercial ventures, from PC games to console games, and is growing in popularity amongst hobby game developers. GameMonkey Script can be downloaded from http://www.somedude.net/gamemonkey. At the time of writing, the most recent version is 1.24a.

Comparison to Lua

As GameMonkey script was originally inspired by Lua, it is useful to highlight the differences between the two environments.

GameMonkey Script Lua
Script Syntax C-like C/BASIC hybrid
Source Language C++ C
Platform Cross-platform; has been compiled and used on PC, PS2, Xbox and GameCube Cross-platform; has been used on many platforms
Numbers int, float double
Array Start Index 0 1
Default Scope local global
Multi-tasking Coroutines (called threads) Coroutines
Garbage Collection Incremental Mark & Sweep Mark & Sweep (made incremental in 5.1beta)
Parser Flex/Bison Custom Parser
Data Access method Global table / function call params Stack access
Statement terminator Semi-colon Optional semi-colon
Ease of host binding:
without 3rd party tool
Moderate Difficult
Ease of host binding:
with 3rd party tool
Simple/Moderate Simple
Community size Small Large
Syntax suited to: C/C++ programmers Beginners and non-programmers
Availability of documentation / example code Low High
Latest version 1.24a 5.1 (beta)
License MIT MIT

Lua has been used successfully in many commercial and amateur game projects, however it can be difficult to use without a third party binding library as its stack-access method can be confusing for people new to scripting. GameMonkey Script aims to address the complexities of Lua whilst still maintaining its inherent power through flexibility.





Introduction to the Language


Contents
  Introduction
  Introduction to the Language
  Expression and Conditional Syntax
  The Table Type
  Simulation with Tables
  Further Exploration

  Source code
  Printable version
  Discuss this article

The Series
  Language Introduction
  Embedding GameMonkey