Inheriting attiributes and the use of namesapces
by Rob Segal · in Torque Game Builder · 10/16/2006 (12:01 am) · 5 replies
Say I have two classes specified in script...
Now I instantiate two objects...
Calling $obj1.print() will indeed print "I'm class A!". As I understand things if I call $obj2.print() shouldn't it also print "I'm class A!" ? For me it doesn't.
function ClassA::print(%this)
{
echo("I'm class A!");
}Now I instantiate two objects...
$obj1 = new t2dStaticSprite()
{
class = ClassA;
}
$obj2 = new t2dStaticSprite()
{
class = ClassB;
superClass = ClassA;
}Calling $obj1.print() will indeed print "I'm class A!". As I understand things if I call $obj2.print() shouldn't it also print "I'm class A!" ? For me it doesn't.
#2
10/16/2006 (7:53 am)
Hmmm... I don't believe I am running 1.1.2. I could be wrong though. Does the version of TGB you are running get printed out in the console when you start up?
#3
Previous versions should work with the above code too, I don't have one installed atm to test it though. What error message do you get when you try "$obj2.print();" ? Have you rechecked your code for any typo's such as missing semi colons?
10/16/2006 (4:46 pm)
Check your console log forQuote:
Torque Game Builder (v1.1.2) initialized...
Previous versions should work with the above code too, I don't have one installed atm to test it though. What error message do you get when you try "$obj2.print();" ? Have you rechecked your code for any typo's such as missing semi colons?
#4
10/16/2006 (9:34 pm)
Wow you know I don't know what I was doing wrong or what I was seeing before but you guys are right. This is working. Sorry for the false alarm and thanks very much for the responses!
#5
Tag: TGB in GPGT
Edit: doh, you beat me to it! Glad you got it working.
10/16/2006 (9:36 pm)
TorqueScript has worked that way for ages. Should work fine in any version of TGB you have.Tag: TGB in GPGT
Edit: doh, you beat me to it! Glad you got it working.
Torque Owner Gary Preston
I tried the above by pasting it at the top of main.cs in the ExampleMyFishDemo
$obj1 = new t2dStaticSprite() { class = ClassA; }; $obj2 = new t2dStaticSprite() { class = ClassB; superClass = ClassA; }; function ClassA::print(%this) { echo("I'm class A!"); } function runtests() { echo("Printing obj1"); $obj1.print(); echo("Printing obj2"); $obj2.print(); }and calling runtests() just after the exec calls in initializeProject. The output in the console was as expected: