Game Development Community

ScriptObject bug? I'm probably just missing something...

by Stephen Nichols · in Torque Game Builder · 03/18/2009 (11:16 am) · 1 replies

Consider the following TorqueScript:

In a file called Ship.cs:
new ScriptObject ( ShipData )
{
    Engine = "DefaultEngine";
};

function Ship::doSomething ( %this )
{
}

In a scene (t2d) file:
...

new t2dStaticSprite(PlayerShip : ShipData)
{
   ...
   class = "Ship";
};

This code works just fine. I end up with a static sprite that is linked to the Ship namespace with a default engine. However, there's one niggly bit here that is making me a sad panda... I want the class "Ship" to be copied as part of the ": ShipData" syntax. But, it's not.

Consider this code that doesn't work:

In a file called Ship.cs:
new ScriptObject ( Ship )
{
    class = "Ship";
    Engine = "DefaultEngine";
};

function Ship::doSomething ( %this )
{
}

In a scene (t2d) file:
...

new t2dStaticSprite(PlayerShip : Ship)
{
   ...
};

Using this code will give me errors about unlinking parent classes and whatnot in Ship.cs. Similarly:

In a file called Ship.cs:
new ScriptObject ( ShipData )
{
    class = "Ship";
    Engine = "DefaultEngine";
};

function Ship::doSomething ( %this )
{
}

In a scene (t2d) file:
...

new t2dStaticSprite(PlayerShip : ShipData)
{
   ...
};

This gives the same error.

Is it just me, or does the ":" copy syntax not copy the "class =" assignment?

I can workaround this, but I'd really like to avoid having my designers setting classes manually. I'd like them to "inherit" the class settings and defaults using the ":" syntax.

Anyone have some wisdom to share on this?

steve

#1
09/09/2009 (9:19 pm)
Hi Stephen,
you should use t2dSceneObjectDatablock instead of ScriptObject, so Ship.cs should look like

datablock (ShipData)
{
    class = "Ship";
    Engine = "DefaultEngine";
};

function Ship::doSomething ( %this )
{
}

And in a scene (t2d) file you can use:

...

new t2dStaticSprite(PlayerShip : ShipData)
{
   ...
};

so designer could have an easier work day :-)

Here you can find some datablock limitations when using class or superclass attribute and, if you need to use a more complex inheritence mechanism, you can find a very good example at this post.