Reference for object oriented scriptobjects and such?
by Jacob Wagner · in Torque Game Builder · 11/24/2006 (1:59 am) · 2 replies
I used to have a copy of some text that matthew langley wrote about scriptobjects and how to use them,
however a search for 'scriptobject' and 'matthew langley' together didn't find it. Basically, the text described how you create scriptobjects, how you inherit values, and what you could do with them.
Is there a new reference to similar material somewhere? I perusal of TDN and the torquescript overview and reference docs didn't seem to turn up anything.
however a search for 'scriptobject' and 'matthew langley' together didn't find it. Basically, the text described how you create scriptobjects, how you inherit values, and what you could do with them.
Is there a new reference to similar material somewhere? I perusal of TDN and the torquescript overview and reference docs didn't seem to turn up anything.
#2
Script objects also have three levels of inheritence... say we created a base class like this
and add some starting values to it
now lets make our own onAdd function attached to this "Entity" object which will get called everytime an entity is created...
then we can create a child class of it, like this
(I did the health and strength that way so it would build off of its class)
run the createEntityClass(); function in the console and you should see this
then you should see this in the console when createOrc(); function is run
now you can create a function like this
then just call it like this
and it will fire when you create an orc
now to test this add
then whatever orcs you created with "createOrc" call ".yell();" on them and you should see the console react properly
11/28/2006 (1:36 pm)
Here is the block I used to post about it (dug it up)Script objects also have three levels of inheritence... say we created a base class like this
and add some starting values to it
function createEntityClass()
{
new ScriptObject(Entity){
health = 100;
mana = 250;
strength = 10;
};
}now lets make our own onAdd function attached to this "Entity" object which will get called everytime an entity is created...
function Entity::onAdd(%this)
{
echo("New Entity added -" SPC %this.getName());
}then we can create a child class of it, like this
function createOrcClass()
{
new ScriptObject(Orc) {
class = Entity;
};
Orc.health = Orc.class.health + 50;
Orc.strength = Orc.class.strength + 5;
}(I did the health and strength that way so it would build off of its class)
run the createEntityClass(); function in the console and you should see this
Quote:
New Entity added - Entity
then you should see this in the console when createOrc(); function is run
Quote:
New Entity added - Orc
now you can create a function like this
function createOrc(%name)
{
new ScriptObject(%name){
class = Orc;
superClass = Entity;
};
}then just call it like this
createOrc(Bob);and if you want to overide the entity onAdd you can do so by adding one to Orc
function Orc::onAdd(%this)
{
echo("New Orc of added -" SPC %this.getName());
}and it will fire when you create an orc
now to test this add
function Entity::yell(%this)
{
echo("This yelled -" SPC %this.getName());
}then whatever orcs you created with "createOrc" call ".yell();" on them and you should see the console react properly
Torque Owner Ben R Vesco
$myObj = new ScriptObject(ANameForIt : ScriptObjectToInherit) { myVar = "1.01"; config = "myConfigDatablock"; };The " : ScriptObjectToInherit" is what I'm not sure will work. Create another script object called that and see.