Game Development Community

Why would I use ScriptObject?

by Storm Kiernan · in Torque 3D Professional · 03/26/2011 (6:51 pm) · 7 replies

What are some good applications of using ScriptObject?

#1
03/26/2011 (7:48 pm)
ScriptObjects are objects which do not physically exist in the level, but can still be used to store and reference data.

Look in AIplayer.cs and then gamecore.cs for "aiManager". That's a good example.
#2
03/26/2011 (8:27 pm)
The gametype code at it's root depends on a ScriptObject to contain the "game object" that subsequent gametype packages modify.
#3
03/26/2011 (8:42 pm)
Would something like an inventory object be a good example of this?
#4
03/26/2011 (8:48 pm)
Sure would.
#5
03/26/2011 (8:49 pm)
Ok, starting to make more sense. Thank you.
#6
03/27/2011 (7:39 am)
They're good to create "custom" objects that have no physical representation. It's the closest you can get to writing classes in TorqueScript:

function Foobar::onAdd(%this)
{
   echo("A foobar "@ %this @" has been created!");
}

function Foobar::doSomething(%this)
{
   echo("Foobar "@ %this @" is doing something!");
}

$myObj = new ScriptObject()
{
   class = Foobar;
};
$myObj.doSomething();
#7
03/27/2011 (11:33 am)
That was helpful, thank you.