Game Development Community

Two scripting questions

by Michael Rogers · in Torque Game Engine · 07/06/2005 (7:05 pm) · 3 replies

I come from a Java background, and I'm used to the notion of defining a class, and then instantiating objects. So, for instance, I might have a class called Foo in a file called Foo.java. In another class, I'd instantiate some Foo objects.

In my (admittedly limited) study of Torque, I've come across numerous examples of how to instantiate an object in scripts using new, but where are do you define these classes? Can you do that in a .cs file? Or are you just restricted to using classes that come with the engine?

Secondly, how do you create a subclass of, say a Player? It looks like you can add methods to a class by simply writing:

function Player::functionName(){ ... }

in a .cs file,

but that isn't really subclassing anything.

Thanks for humoring and helping a newbie. If there's a better forum to post this in, please let me know.

Michael

#1
07/06/2005 (7:45 pm)
Most classes are created in the engine code and instantiated in script (as you mentioned)

%player = new Player() {
      dataBlock = PlayerDataBlock;
      client = %this;
   };

for subclassing/iheritance it would look something like

datablock PlayerData(PlayerDataBlock : OrcPlayerDataBlock)
{
	.....
};

now PlayerDataBlock would contain its own cruft and inherit that of OrcPlayerDataBlock as well

Hopefuly I answered your question, if not toss in a followup round ;)
#2
07/06/2005 (8:24 pm)
Thanks for your reply, Ron. I'm *very* new too all this, so I'm going to try and paraphrase and let me know if I've got it right:

1) PlayerDataBlock is a type of PlayerData datablock, and so it has all the variables defined in PlayerData (and ShapeBaseData).
2) What makes PlayerDataBlock unique is those variables defined in { ... } plus those inherited from OrcPlayerDataBlock.

Are these right? This looks like multiple inheritance, sort of ...

But my two questions have now generated two more:

1) In Finney's book (p. 129) he says that the second term, the OrcPlayerDataBlock in this example, should be a *super* class of PlayerData. In my (Java) world, an OrcPlayerDataBlock would most definitely be a subclass of PlayerData. Does Finney mean subclass?
2) What about methods? So far all that's being inherited are methods, as I understand it.

I've just glanced at the Liquid Creations tutorial on the subject, and it's pretty helpful. My attempts to learn Torque make me feel like I'm a prospector, panning for nuggets (of information, not gold).

What would help me (and perhaps others) would be for someone who is proficient in both Java (or C++) and Torque Script to give a detailed comparison of the two.

Thanks again for your help,

MIchael
#3
07/07/2005 (3:07 am)
I have the same problems, coming from java or c++ or objectiv-c it is difficult to understand, the scripting-language or making for example just another tree via scripting.