Class definition functions

Each class provided by the plugin is defined by a set of function pointers. WME calls these functions whenever it needs the class to perform some action. For example, if WME needs to create a new object of this class, it calls its Construct() method, when WME saves/loads game, it calls the Serialize() method etc. The plugin sends a set of function pointers to WME via the GetClassDefinition() function described here.

Each class has to provide the following functions:


unsigned long Construct(IWmeObject* Owner, IWmeGame* Game, IWmeScript* Script, IWmeStack* Stack)

This function is called by WME when it needs to create a new scripting object of this class. In the example above, the line

    var SnowGen = new Snow(100);

invokes a Construct() method of the "Snow" class.

Typically you create an initialized instance of your internal class in this function.

This function receives the following parameters:

This function returns an ID of the newly created object. Typically this returned value is the pointer to the newly created object.


unsigned long ConstructEmpty(IWmeObject* Owner, IWmeGame* Game)

This function is called by WME when it restores a saved game. In that case, WME recreates the entire object graph by creating empty objects and then calls their Serialize() methods to restore their state from a savegame file. Typically you create an empty instance of your internal class in this function.

This function receives the following parameters:

This function returns an ID of the newly created object. Typically this returned value is the pointer to the newly created object.


void Destruct(unsigned long ID)

This function is called by WME when it needs to delete an existing scripting object. Typically you delete the instance of your internal class in this function.

This function receives the following parameter:


bool CallMethod(unsigned long ID, const char* MethodName, IWmeScript* Script, IWmeStack* Stack)

This function is called by WME whenever a script is calling a method of the plugin object.

This function receives the following parameters:

This function returns true if it was able to handle the requested method call or false if the method name was invalid.


bool SetProperty(unsigned long ID, const char* PropName, IWmeValue* Value)

This function is called by WME whenever a script is attempting to set a property of the plugin object.

This function receives the following parameters:

This function returns true if it was able to set the requested property or false if the property name was invalid.


bool GetProperty(unsigned long ID, const char* PropName, IWmeValue* Value)

This function is called by WME whenever a script is attempting to access a property of the plugin object.

This function receives the following parameters:

This function returns true if it was able to return the requested property or false if the property name was invalid.


bool Serialize(unsigned long ID, IWmeSerialMgr* SerialMgr)

This function is called by WME whenever it needs to serialize or deserialize the contents of the plugin object (when saving/restoring game).

This function receives the following parameters:

This function returns true if the object was successfully serialized/deserialized.


bool ReceiveEvent(unsigned long ID, EWmeEvent EventID, void* EventData1, void* EventData2)

This function is called by WME whenever any of the subscribed events occurs.

This function receives the following parameters:

This function returns true if it handled the event.