Game Development Community

Does Torque Script support oop by its own?

by M Mahmud Hasan · in Torque Game Engine · 12/28/2006 (11:02 am) · 6 replies

Hi,

I am sorry to asking a very basic question but I am totally confused about it.
Does Torque Scriot supports Object Oriented programming (like creating class and then instanciate it and then use it like regular C++ code) by itself ? ot Do I have to upgrade the engine code (there is a resource by Bryan Edds) to support OOP by Torque script?

I really need the answer. Help is greatly appreciated.

#1
12/28/2006 (6:45 pm)
You can use OOP if you want with TorqueScript but it doesn't force it.

i.e. you can do something like this

new ScriptObject (Foo)
{
i = 10;
};

function Foo::Bar(%this)
{
return i;
};

and in your main game loop have

%FooPtr = Foo.getID();

and never use the global reference to your Foo scriptObject and just pass the ID you got.

If it is inheritance you want, TorqueScript by default only allows 2-deep inheritance, I think, and there is an OOP resource that allows multiple inheritance and unlimited datablock/scriptobject inheritance
#2
12/28/2006 (11:56 pm)
It does have some support for OOP. The resource adds many helpful features, but what's there was more than enough to develop several major games with.
#3
12/29/2006 (1:20 am)
Thanks a lot for the quick reply. I got exactly what I wanted from your answers.
I just needed to implement a data structer which might be easier to implement through OOP.

Thank you guys!
#4
12/29/2006 (1:23 am)
Another question. what is the good way to implement private and public function in a script object. Does it have similar functionality in torque script as that of C++/Java?
#5
12/29/2006 (11:52 am)
That OOP resource may support the private/public aspects but TorqueScript on its own only has 1 type of member variable.

And if your next question is about constants, no, there aren't any, you have to simulate them, same thing with enumerations


But what you can do about private member variables, is never access them by the ScriptObject.VariableName accessor and create ScriptObject.getVariableName() and ScriptObject.setVariableName() and use those instead of directly accessing the variable
#6
12/29/2006 (3:37 pm)
Well TorqueScript isn't a pure OOP oriented , is more like a Prototype oriented