Skip to content
nikki93 edited this page Sep 13, 2010 · 3 revisions

This page describes the generic NGF Python API, which comes ‘for free’ if you use NGF Python. Games would usually build upon this to create an interface specific to themselves.

Functions

Ngf.createObject(type, name, pos, rot, props)
Creates a GameObject of the given type (as a string), name, ("" if no name), position (Ngf.Vector3), rotation (Ngf.Quaternion), and properties. The property list is a Python dict, similar to what you would enter for the object in Blender. For example, { “colour”: “0.4 0.2 0.1” }.

Ngf.destroyObject(obj)
Destroys the GameObject pointed to by the given handle.

Ngf.getObject(id)
Ngf.getObject(name)
Retreives a handle to the GameObject with the given ID (integer) or name (string).

Python GameObject Events and Methods

The NGF GameObject is the base for all Python GameObjects in the application. So, all GameObjects have the following properties.

Events

An event is a function in the GameObject’s script (written in Blender) that is run when something happens. So, you can have ‘def create(self): print self.getID()’ to make the GameObject print its ID when created. These are events that all GameObjects fire. The ‘collide’ event, however, is only available for physical objects.

init(self):
Called when the GameObject is first created. At this point, the other GameObjects may or may not have been created. If your code requires some other GameObject to exist, best use the ‘create(self):’ event. This event is also called when the GameObject is created due to deserialising (loading from a save file).

create(self):
Called after the entire level is loaded. This is not called when deserialising.

destroy(self):
Called when the GameObject is destroyed.

utick(self):
Called every ‘tick’ (frame), when the game is not paused.

ptick(self):
Called every tick, when the game is paused.

collide(self, other):
Called when a physical GameObject collides with another. ‘other’ is a handle to the other GameObject.

Methods

These are methods you can call on a GameObject. For example, ‘player.getID()’. These methods are available for all GameObjects.

getID()
Returns the ID of the GameObject.

getName()
Returns the name of the GameObject.

addFlag(flag)
Adds the given flag (a string) to the GameObject flags.

hasFlag(flag)
Returns whether the GameObject has the given flag.

removeFlag(flag)
Removes the given flag from the GameObject flags.

getFlags()
Returns a string containing all the flags the GameObject has delimited by ‘|’, starting and ending with ‘|’. For example, “|Bomb|Dangerous|”.

getProperty(name, index, default)
Gets the string value with the given index belonging to the given property, and if not found, returns the default value. For example, ‘light.getProperty(“colour”, 1, “0.5”)’ would return the green coefficient of the light’s colour (index starts from ‘0’), and “0.5” if the property wasn’t found.

Clone this wiki locally