OOP does not work in the TorqueScript
by Alex Malinovsky · in Torque Game Builder · 01/11/2008 (12:07 am) · 5 replies
Trying to separate busyness-logic and view layers
For drawing object used:
for logic without drawing:
When 2nd code executing then following error message occur:
Anybody know how to resolve this problem?

For drawing object used:
%ball = new t2dStaticSprite()
{
class = "CBall";
superclass = "CBallLogic";
};for logic without drawing:
%ball = new ScriptObject()
{
class = "CBallLogic";
};When 2nd code executing then following error message occur:
Namespace::unlinkClass - cannot unlink namespace parent linkage for CBallLogic for t2dStaticSprite. Error: cannot change namespace parent linkage of CBallLogic from t2dStaticSprite to ScriptObject.
Anybody know how to resolve this problem?

#2
I know about this chains, but I need to use cballogic standalone (game logic), and as static sprite too.
I don't wont write the same code twice, or create ClogicBall member for CBall object., because have some another classes which can work with CLogicBall and CBall.
01/11/2008 (7:40 am)
Thank you Patrik,I know about this chains, but I need to use cballogic standalone (game logic), and as static sprite too.
I don't wont write the same code twice, or create ClogicBall member for CBall object., because have some another classes which can work with CLogicBall and CBall.
#3
Also note that TorqueScript namespace inheritance can't go more than one layer deep (so CLogicBall->CBall works, but CLogicBall->CBall->CPlayerBall wouldn't). If you need two or more layers, you'll have to add the classes into the engine code, although the functions can still be in script.
In either case, if you want logic that works with different types of objects (t2dStaticSprite and t2dAnimatedSprite CBalls, for instance), then it's better suited as a behavior than a class.
01/11/2008 (1:18 pm)
You could just create CLogicBall objects as t2dStaticSprites. Slight amount of wasted memory, but unless you're creating vast numbers of them it shouldn't be noticable.Also note that TorqueScript namespace inheritance can't go more than one layer deep (so CLogicBall->CBall works, but CLogicBall->CBall->CPlayerBall wouldn't). If you need two or more layers, you'll have to add the classes into the engine code, although the functions can still be in script.
In either case, if you want logic that works with different types of objects (t2dStaticSprite and t2dAnimatedSprite CBalls, for instance), then it's better suited as a behavior than a class.
#4
Quoted for truth--this would be the way to go :)
01/11/2008 (3:07 pm)
Quote:
In either case, if you want logic that works with different types of objects (t2dStaticSprite and t2dAnimatedSprite CBalls, for instance), then it's better suited as a behavior than a class.
Quoted for truth--this would be the way to go :)
#5
Yes I tried to create CLogicBall objects as t2dStaticSprites it works, but many CLogicBall object needed and this is not universal solution.
Also I thought about behavior too... I think this is a good solution for now, but it's easy to use from Level Editor, but not so easy in TorqueScript for ScriptObjects.
Thanks anyway :)
01/11/2008 (10:16 pm)
Thank you Kalle,Yes I tried to create CLogicBall objects as t2dStaticSprites it works, but many CLogicBall object needed and this is not universal solution.
Also I thought about behavior too... I think this is a good solution for now, but it's easy to use from Level Editor, but not so easy in TorqueScript for ScriptObjects.
Thanks anyway :)
Torque 3D Owner Patrick Shaw
I believe that your first block of code generates a the following class chain:
simobject -> (several other classes) -> t2dsceneobject -> t2dStaticSprite-> cballogic -> CBall
and the second tries to create the following
simobject -> scriptobject -> cballogic
The error is because "cballogic" cannot be a child in two separate chains. There are several different ways of resolving this. If you describe your goals in a little more detail, I can help point you in the right direction.