Quote:
Yeah, it's a bit of a waste though. A remember Witchlord saying at one point that he was going to seperate the global script variables from the engine; that would allow scripts to be shared and still have unigue global data per entity. It would be perfect.
That would be awesome, let's hope that will happen.
In the meantime I will probably continue with the second alternative.
When it comes to creation of GameObjects I do use several modules.
My GameObjects are componentbased and to simplify the creationprocess I've created some template functions that take an empty gameobject and a custom keyvaluepair table as parameters. The template functions are each put inside their own module which is named the same as their source file.
Like this...
// ==========================================================// SimpleMesh Template// ==========================================================void Setup(GameObject@ go, Table params){ if( not params.HasString("meshfile") ) { Print("Missing required param <meshfile> for GameObject <" + go.GetName() + ">"); Print("Using default 'cube.mesh' instead"); params.SetString("meshfile","cube.mesh"); } SceneNode@ node = go.AddSceneNode("MainNode"); if( params.HasVector3("position") ) node.SetPosition( params.GetVector3("position") ); Entity@ ent = go.AddEntity("Mesh", params.GetString("meshfile") ); ent.AttachToSceneNode(node); if( params.HasString("material") ) ent.SetMaterial( params.GetString("material") ); else ent.SetMaterial("BaseWhite");}
And to create an instance of a "SimpleMesh" GameObject I do like this...
// ==========================================================// Main script// ==========================================================void Main(){ Table params; params.SetString( "meshfile", "monkey.mesh" ); params.SetString( "material", "GreenSkin" ); params.SetVector3( "position", Vector3(0,0,90) ); GoMgr.CreateGameObject("Monkey","SimpleMesh.as",params);}
The second parameter "SimpleMesh.as" is actually the module name in which I call the function Setup()
This way I can define any kind of gameobject, from a simple rendered mesh to more advanced gameobjects like a physics-driven vehicles. Passing a collection of parameters allow me create loads of different gameobjects with just a slight modification of the creation parameters.
For example to create another monkey but with another material I just add two lines to the code above...
// ==========================================================// Main script// ==========================================================void Main(){ Table params; params.SetString( "meshfile", "monkey.mesh" ); params.SetString( "material", "GreenSkin" ); params.SetVector3( "position", Vector3(0,0,90) ); GoMgr.CreateGameObject("Monkey","SimpleMesh.as",params); params.SetString( "material", "BlueSkin" ); GoMgr.CreateGameObject("SecondMonkey","SimpleMesh.as",params);}
It works so far... :)