How does main.cs's OnStart() call the other OnStart() functions
by Michael Rogers · in Torque Game Engine · 07/09/2005 (9:32 am) · 6 replies
Hi, All:
I'm looking at CH4's root main module. Finney states that the call to OnStart(), on the very last line, will "call all versions of OnStart()". But the OnStart() function defined in the root main module is just a stub, so how do the others get called?
Related to this, I can see that control/main.cs calls the root main module's OnStart(), with Parent::. But what determines that the root main module *is* the parent of control/main.cs.
Thanks for any enlightenment,
Michael
I'm looking at CH4's root main module. Finney states that the call to OnStart(), on the very last line, will "call all versions of OnStart()". But the OnStart() function defined in the root main module is just a stub, so how do the others get called?
Related to this, I can see that control/main.cs calls the root main module's OnStart(), with Parent::. But what determines that the root main module *is* the parent of control/main.cs.
Thanks for any enlightenment,
Michael
About the author
#2
I understand how things work with packages. For instance, after
then package1 is the parent of package2, because it was activated first.
When it comes to exec()'ing scripts, are you saying that if I do:
that path1/main.cs's functions are automatically deemed the parent of path2/main.cs's?
And, as long as I'm wildly thrashing about trying to understand this, what namespaces are associated with the functions in path1/main.cs and path2/main.cs?
As before, any and all help would be greatly appreciated. I'm desperate, and on a deadline :-)
Michael
07/09/2005 (12:03 pm)
Thanks for your response, Bryce. I guess I'm still confused about what makes something a parent, relative to something else. In Java and C++, it's obvious: with Torque Script, I don't quite yet grasp it. I understand how things work with packages. For instance, after
activatePackage(package1); activatePackage(package2);
then package1 is the parent of package2, because it was activated first.
When it comes to exec()'ing scripts, are you saying that if I do:
exec("path1/main.cs");
exec("path2/main.cs");that path1/main.cs's functions are automatically deemed the parent of path2/main.cs's?
And, as long as I'm wildly thrashing about trying to understand this, what namespaces are associated with the functions in path1/main.cs and path2/main.cs?
As before, any and all help would be greatly appreciated. I'm desperate, and on a deadline :-)
Michael
#3
basically, by the time onstart() is called in main.cs, it has been overidden by another onstart() declared from a package which was activated after the root onstart() was declared. the new onstart() eventually calls the root onstart() using successive calls to Parent::function.
07/09/2005 (1:55 pm)
Michael your understanding of packages actually represents the behavior of functions contained in those packages. in other words, in the example you gave, package1 isnt a parent of package2, but if the two packages have functions of the same namespace, the instance of the function in package2 will override the namespace and will be the parent of the function in package1 because that package was activated LAST. if you simply declare two functions of the same namespace, the second one will erase and overwrite the first one. using packages, you can call both versions of the function by placing a call to Parent::function() in the package 2 version of the function. basically, by the time onstart() is called in main.cs, it has been overidden by another onstart() declared from a package which was activated after the root onstart() was declared. the new onstart() eventually calls the root onstart() using successive calls to Parent::function.
#4
Just one small point: as far as parents in the packages are concerned, if package2 overrides package1, then doesn't that make package2 a child? That's the terminology in C++ and Java.
Thanks again,
Michael
07/09/2005 (2:48 pm)
Thanks very much, Sean: from your explanation, and a quick re-read of Joel Baxter's tutorial, I now get why OnStart() is doing what it's doing.Just one small point: as far as parents in the packages are concerned, if package2 overrides package1, then doesn't that make package2 a child? That's the terminology in C++ and Java.
Thanks again,
Michael
#5
07/09/2005 (2:59 pm)
I wouldnt consider packages to be child or parent because packages themselves dont follow any kind of hierarchy. its the functions contained in the packages which may become part of a hierarchy.
Torque Owner Bryce "Cogburn" Weiner
It is that process establishes the parent for all subsequent calls to onStart.
Now I don't have the book... but thats how it works. :)