Game Development Community

dev|Pro Game Development Curriculum

Humorous Distraction: Stupid Package Tricks

by Demolishun · 08/13/2013 (1:28 am) · 3 comments

This to me is a humorous distraction I made use of while developing some GUI code in T3D. I found that I wanted to call the previous version of a function overridden by a package from within the new function that overrode it.

Well, you can:
function testfunction()
{
  echo("World");
}
package testpackage1
{
  function testfunction()
  {
    echo("Hello");

    deactivatePackage(testpackage1);

    testfunction();

    activatePackage(testpackage1);
  }
};

I needed this because I wanted to override a method of the mission loading dialog. The function that replaced this called a new function. I still wanted the old function to run to add the file choices for loading a mission. So I used this method to call the old function first. Then in my method I add choices available from a database table. Eventually I will load purely from a database table, but this trick allows me to be more flexible during development. I find it kind of humorous that this is possible. It is a good thing.

About the author

I love programming, I love programming things that go click, whirr, boom. For organized T3D Links visit: http://demolishun.com/?page_id=67


#1
08/13/2013 (7:03 am)
Or:
function test() {
   echo("test");
}
package destructo {
   function test() {
      echo("destructo");
      Parent::test();
   }
};
activatePackage(destructo);
I do like your way better (points for audacity!), but this is the way it's supposed to be done, I think.
#2
08/13/2013 (9:38 am)
Ah crap, I didn't know there was a Parent concept for packages. Hmmm...

Edit:
There is a lot of stuff that is not in the T3D Script Manual:
- I could not find '->' or '-->' operator explanations.
- I have never seen anything in there on 'Parent::' for packages.

Does Parent:: work with methods?
Parent::ChooseLevelDlg::onWake();



#3
08/13/2013 (1:34 pm)
I am going to admit something here dB. My callback that replaced the ChooseLevelDlg::onWake function calls Python code. So I am actually unloading/loading the package from within Python. I searched after you showed me how to do this in TS using Parent:: and I can do this fine. But there is no direct translation for doing this from Python at all. My best bet is adding the Parent::onWake() method inside my package version of ChooseLevelDlg::onWake. So I may have to sit down and figure out a way to add function calls to package name spaces and figure out how to call previous version of functions in that namespace. Up to this point I have completely avoided the package system altogether. Or I can just abuse it like I am doing now...