Game Development Community

dev|Pro Game Development Curriculum

Script Inheritance Extension and Object-Oriented Scripting Methodology

by Bryan Edds · 09/01/2004 (8:37 pm) · 3 comments

Download Code File

THIS RESOURCE IS DEPRECATED! Find the new 3.0 version HERE.

Initially, all script inheritance functionality was put into the ScriptObject, and unfortunately, it only allowed one layer of inheritance. While it was handy for very specialized tasks, I could not help but wonder what I could do with it. Harold and I discussed the current capabilities, and he quickly saw that with just the smallest bit of tinkering, multi-layered inheritance was possible. So, like the insane genius he is, he went in, did a bit of C++ coding, and made multi-layered inheritance work... well, almost. Unfortunately, there was another task that remained which would be needed to be done in order to help the ConsoleEval object find the methods of multi-layered inheritance when the method was not defined at all levels of inheritance. So with a bit of direction from Ben, I went into ConsoleEval, and updated it to handle the new capabilites in just a couple hours. No problem.

And I figured I might just stop there... but my curiousity drove me forward. I asked myself, "Why can't I put this feature into ALL objects that can be accessed in script?" So I tried it a couple different ways, and found one that worked expertly! I just moved all the inheritance functionality implemented in ScriptObject backwards into SimObject. Good stuff.

So, with the code extension considered by themselves, the only thing you got here is some fixed inheritance features that Torque was probably meant to have in the first place. The great thing about this is that you can use these features only if you want to - if you're not a big fan of inheritance, you just ignore it. Problem solved. It just all depends on what you want to do and how you do it. For OO maniacs like me, it's better to have the feature available than not, so long as it doesn't get in anyone else's way. Which brings up another good thing, this code extension is %100 backwards compatible with all your old script code. All you have to do is copy the zipped "engine" folder into you Torque directory, do a rebuild, and you're done.

So, that, in a nutshell, is what has been done in the extension. But I told you that story so I could tell you this one -

When I had arrived seriously on the Torque scene after developing some GUI stuff on the Q game engine, I took a very hard look at what capabilities Torque script offered its programmers. Although I did not, at the time, know that inheritance allowed only one layer, I knew that with a bit of methdological standardization, a form of object-oriented programming in script was possible. This all, of course, is before I met Harold. So, I pounded out the necessary disciplines that I thought would be a great way to achieve OO in script. Only after that, I had someone explain to me that Torque's implementation of scripting inheritance, while it would not stop me from using this methodology, would severely limit how useful the methodology would be. And that's when I met Harold... and ya'll know the rest :)

So download the zip, follow the readme.txt file, and take a look at the sample tsoo.cs file to see the new OO methodology in use. I've tried to include all the explanation I could, but if anyone has anyone questions, feel free to contact me here, or even privately. I'll be happy to answer any questions or concerns as to the hows, whys, or wtfs :D

Also, I've tested this code quite a bit, BUT, that does not mean it will work for you. Since this code has only been narrowly tested, it is highly advised that make sure to read and follow the code rollback instructions in case you encounter a big problem with the code. I cannot guarantee any amount of success with this since I haven't tested it out on your personal machine with your personal project :D

Thanks again to Harold for the help - it was his initial code example that springboarded this entire project. Thanks also to Ben, definitely for the encouragement to do it my way and go allll the way with it. And BIG thanks to the community for all the help for getting my newbie-arse up to speed on the inner workings of Torque.

Finally, thank you for checking out my resource, and I hope it does the community as much good as it will for me.

Keep on Torquin' in the free world :)

#1
09/02/2004 (1:34 am)
Wow, I was wondering if this resource would ever come back :) I've kept the link in my DL manager the whole time.
#2
09/02/2004 (5:33 pm)
Bryan/Labby,

This is crankin! I've got to give this a go when I get a chance.

[HOW]EdM|EGTGE
#3
05/05/2005 (4:22 pm)
THIS RESOURCE IS DEPRECATED! Find the new 3.0 version HERE.