Beginners question: execs and parents recursion?
by NoobGank · in Torque Game Engine · 11/15/2004 (12:47 pm) · 7 replies
Hi could someone please help me with this one - I know its probably fairly basic but it would help enormously.
I know from the 3DGPAIO book that in the top level main.cs we exec a few other filex (in Kenneth Finneys) project for example (ch4) we exec common/main.cs and control/main.cs. I understand this compiles these files and effectively includes them. So when OnStart(); is called it effectively calls each instance of this function in each namepsace or is it namespace (I think - pls confirm).
When I look in common/main.cs its OnStart function has 'Parent::OnStart();'. What is the Parent in this case? Is it the super class (parent) of this package which is'. I can't see that this package (Common) derives from or extends another file or package - like you would see in something like Java, i.,e. Super.onStart().... The only thing I can think is that Parent means the file that loaded it? i.e. the top level Main.cs? Is this correct.
If this is correct then you have the parent (i.e. Main.cs) calling OnStart() in all its exec'd files, but then each of these calling OnStart in their parent, which would be Main.cs again? Some kind of weird recursion follows. I must have this wrong - can anyone please help my understanding?
I'm on that task of first steps of wrapping my head around the scripting so please be patient. I've developed with many scripting lanaguages over the years but this is quite diffferent to those I am used to and my C and C++ is rusty ;-).
Many thanks,
KC
I know from the 3DGPAIO book that in the top level main.cs we exec a few other filex (in Kenneth Finneys) project for example (ch4) we exec common/main.cs and control/main.cs. I understand this compiles these files and effectively includes them. So when OnStart(); is called it effectively calls each instance of this function in each namepsace or is it namespace (I think - pls confirm).
When I look in common/main.cs its OnStart function has 'Parent::OnStart();'. What is the Parent in this case? Is it the super class (parent) of this package which is'. I can't see that this package (Common) derives from or extends another file or package - like you would see in something like Java, i.,e. Super.onStart().... The only thing I can think is that Parent means the file that loaded it? i.e. the top level Main.cs? Is this correct.
If this is correct then you have the parent (i.e. Main.cs) calling OnStart() in all its exec'd files, but then each of these calling OnStart in their parent, which would be Main.cs again? Some kind of weird recursion follows. I must have this wrong - can anyone please help my understanding?
I'm on that task of first steps of wrapping my head around the scripting so please be patient. I've developed with many scripting lanaguages over the years but this is quite diffferent to those I am used to and my C and C++ is rusty ;-).
Many thanks,
KC
#2
I know OO, so I guess maybe I'm trying to draw analogies. Everyone is always comparing Torque to C++. I've worked with many scripting languages through the years - and actually work on the product development of one now - this time for digital interactive tv.
I guess at the moment I'm trying to differentiate between classing and sub-classing, names spaces and packages. Once I get my head around it I'm going to submit a resource that explains the difference.
Cheers,
KC
11/16/2004 (1:13 pm)
Mmm to be honest not really - yet - maybe a bit. The main.cs does not even list a package name - I guess its some kind of default package? So what happens when more than one package is loaded? You say its 'implicitly the parent' because its the first loaded. What about when its not - or there is more than one loaded?I know OO, so I guess maybe I'm trying to draw analogies. Everyone is always comparing Torque to C++. I've worked with many scripting languages through the years - and actually work on the product development of one now - this time for digital interactive tv.
I guess at the moment I'm trying to differentiate between classing and sub-classing, names spaces and packages. Once I get my head around it I'm going to submit a resource that explains the difference.
Cheers,
KC
#3
Stuck right now dealing with the exact type of thing--I'm loading in datablocks, no errors, warnings or anything, but when I go to use those datablocks, I get a warning "xxxBlock is not in GameBaseData", etc.
It's got to be a namespace thing, but damned if I can figure out where!
11/16/2004 (1:35 pm)
@KC: Please please when you do let me know ;)Stuck right now dealing with the exact type of thing--I'm loading in datablocks, no errors, warnings or anything, but when I go to use those datablocks, I get a warning "xxxBlock is not in GameBaseData", etc.
It's got to be a namespace thing, but damned if I can figure out where!
#4
I'm still getting into all of this but if I do work it out I'll let you know - but from readin your posts you are way ahead of me on the curve here. Also like Ben, I'm struggling with trying to not play HL2!
Sounds like you'r on the right track though. The documentation for GameBaseData says the following.. "Linking datablock's namepsaces to the namespace of their C++ class, so that datablocks can expose script functionality."
11/16/2004 (9:18 pm)
Hehehhe - damn - Stephen you were next on my hit lsit for asking how on earth that fits together!I'm still getting into all of this but if I do work it out I'll let you know - but from readin your posts you are way ahead of me on the curve here. Also like Ben, I'm struggling with trying to not play HL2!
Sounds like you'r on the right track though. The documentation for GameBaseData says the following.. "Linking datablock's namepsaces to the namespace of their C++ class, so that datablocks can expose script functionality."
#6
It's best to unload packages in the order they were loaded.
What you'll see being called is (in each case, in order):
foo();
SomePackage1::foo(); foo();
SomePackage2::foo(); SomePackage1::foo(); foo();
SomePackage1::foo(); foo();
foo();
Hopefully this explains what the Parent:: keyword does. It lets you call up to the previously active implementation of a function or method in TorqueScript. That might be something inside a package, or something outside of a package.
@Stephen: No namespacing in TorqueScript, thus unlikely that your problems are related to namespacing.
@Both of you: TorqueScript is really very simple. Be careful that you aren't accidentally adding complexity to your understanding of it. :)
11/17/2004 (1:16 am)
@KC: Here, let me give you an example...function foo()
{
echo("A function!");
}
package SomePackage1
{
function foo()
{
echo("I'm overriding, but I still call... (1)");
Parent::foo();
}
};
package SomePackage2
{
function foo()
{
echo("I'm overriding, but I still call... (2)");
Parent::foo();
}
};
foo();
activatePackage(SomePackage1);
foo();
activatePackage(SomePackage2);
foo();
deactivatePackage(SomePackage2);
foo();
deactivatePackage(SomePackage1);
foo();It's best to unload packages in the order they were loaded.
What you'll see being called is (in each case, in order):
foo();
SomePackage1::foo(); foo();
SomePackage2::foo(); SomePackage1::foo(); foo();
SomePackage1::foo(); foo();
foo();
Hopefully this explains what the Parent:: keyword does. It lets you call up to the previously active implementation of a function or method in TorqueScript. That might be something inside a package, or something outside of a package.
@Stephen: No namespacing in TorqueScript, thus unlikely that your problems are related to namespacing.
@Both of you: TorqueScript is really very simple. Be careful that you aren't accidentally adding complexity to your understanding of it. :)
#7
Would I be right in describing it this way - its almost like dynamic overiding of the last implementation of the method. i.e. calling Parent::doSomething() will always call the last implementation made active?
11/17/2004 (1:11 pm)
Thanks for the example Ben - clearer now I think. I'm bound to crash my mental model a few more times before its all crystal but that does help. So let me try this on you .... Would I be right in describing it this way - its almost like dynamic overiding of the last implementation of the method. i.e. calling Parent::doSomething() will always call the last implementation made active?
Associate Kyle Carter