Calling parent

Okay, I know you can call parent on a function in a package, but can you do the same with a script?
Main reason, I want to edit a script in another script, without messing with the original. I know I could just place a new one into the mod folder, but I would rather just edit it within an autoexeced script. Anyway to do this without some weird and complicated code?

Comments

  • look at the gametype codes.
  • If you mean,
    function DefaultGame::activatePackages(%game)
    {
       // activate the default package for the game type
       activatePackage(DefaultGame);
       if(isPackage(%game.class) && %game.class !$= DefaultGame)
          activatePackage(%game.class);
    }
    
    function DefaultGame::deactivatePackages(%game)
    {
       deactivatePackage(DefaultGame);
       if(isPackage(%game.class) && %game.class !$= DefaultGame)
          deactivatePackage(%game.class);
    }
    
    Then that is neat, but not what I wanted. I wanted to know if you can go into a script, write,
    Parent::SomeScriptOrSomething;
    
    Or something similar to that, so that I can package some code, not necessarily functions, and call the parent to be another script. Where it will look at the script and then replace some part of it with a part I want. The reason I don't do it for a function, is because the lines I want are not in a function.

    If that isn't what you meant, I'll take another look.
  • Nope, you need a package.
  • Er, do you mean that I need a package to call parent at all? If so, I know that, I was just wondering if you could call parent on a script in a package. Like,
    package Blah
    {
    Parent::ScriptOrSomething;
    
    Code Stuff
    };
    activatepackage(Blah);
    

    If you do mean that I can't call parent on a script at all, dangit......
  • edited October 2009
    You can use parent in normal code, but only in object functions...

    This code
    function Foo::Bar(%this)
    {
        echo("Foo::Bar");
    }
    
    function Block::Bar(%this)
    {
        parent::bar(%this);
        echo("Block::Bar");
    }
    
    $temp = new ScriptObject()
    {
        class = "Block";
        superclass = "Foo";
    };
    
    $temp.bar();
    

    would result in the following echoed to the console:
    Foo::Bar
    Block::Bar
    

    On a side note, after you create the first object "linking" the namespaces Foo and Block, you can also call Block::Bar() and get the same results.
    Otherwise, you get an unknown command warning echoed to the console.


    If you want to "include" various script into another, parent and packages don't do that.
    The parent keyword simply jumps to the parent frame of reference (in a package, that's the function you've wrapped; in a class method, that's the parent/super class version of the method) and then returns back to the calling frame of reference.

    If it's your script, you have two choices:
    • Break the code into a separate file, and exec that when you need it
    • Turn the block of code into a function
Sign In or Register to comment.