T3D/Scripters/T3D Script Hierarchy

From TDN

Torque3D has a seldom mentioned ... or at least, not mentioned enough ... hierarchy, and a very important hierarchy at that. Getting it wrong stops stuff from working and won't always give you a warning about it not working (eg: audio does not play).


If you look in "art/datablocks/datablockExec.cs" (the same goes for "art/scripts/server/scriptExec.cs") you'll notice that things are exec'd in order, and there's some comments there to help out. However it really needs a "BIG WARNING SIGN" that failing to group things together in the correct section will lead to failings in-game.


This occurs because a datablock cannot call something that was not declared before itself.


Notice the hierarchy of audio -> particles/FX -> gameObjects(triggers) -> rigid -> item -> staticShape(added by me) -> weapons -> players -> vehicles.


// Load up all datablocks.  This function is called when
// a server is constructed.

// Do the sounds first -- later scripts/datablocks may need them
exec("./audioProfiles.cs");

// Do the various effects next -- later scripts/datablocks may need them
exec("./particles.cs");

exec("./environment.cs");
exec("./triggers.cs");

// Add a rigid example
exec("./rigidShape.cs");

exec("./health.cs");

// <----- YORKS ADDED: StaticShapeClassObjects should go here! to avoid issues

// Load our supporting weapon datablocks
exec("./weapon.cs");

// Load the weapon datablocks
exec("./weapons/rocketLauncher.cs");
exec("./weapons/Soldier_gun.cs");
exec("./weapons/grenadeLauncher.cs");

// Load the default player datablocks
exec("./player.cs");

// Load our other player datablocks
exec("./aiPlayer.cs");

// Load the vehicle datablocks
exec("./vehicles/defaultCar.cs");
exec("./vehicles/cheetahCar.cs");


So if you've created a new weapon/ammo it needs execing with the rest of the weapons/ammo.


This hierarchy is mirrored inside actual weapon files, which often contain all necessary data for the weapon (eg: audio, particles, items, projectiles). Failure to observe this hierarchy means failure for the weapon to work. The main issue here can be particles which have a whole host of elements.


//In order!
//audio
//particles 
//emitters
//debris
//explosions/splash


If you are using elements that are "pooled" or outside of the weaponObject's cs file, you'll still need to respect the hierarchy and have the seperate scripts exec'd in the correct order in "datablockExec.cs", and of course the same goes for "scriptExec.cs".


QUOTE: "Not an exact hierarchy per se but unlike a script method a given datablock cannot call for something that wasn't already declared before itself."