Announcement

Collapse
No announcement yet.

Scoping issue: is this even possible?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Scoping issue: is this even possible?

    Hi all,

    So my heirarchy looks something like this.

    class MyPawn extends Pawn;
    function Foo()
    { ... }

    class MyPlayerPawn extends MyPawn;
    function Foo()
    { ... }

    class MyPlayerController extends PlayerController;

    MyPlayerController's 'Pawn' member variable is referencing a MyPlayerPawn type.

    Here is my problem:

    I'm trying get the Controller's Pawn (Pawn is referencing a MyPlayerPawn type) variable to call an overridden function that is defined both in MyPawn and in MyPlayerPawn. In this case I want to call the MyPawn version of the function Foo(). Or the function one class up in my heirarchy.

    I tried using 'super' but UCC complains that super can only be used with self or within the scope of the class where it is being used.

    I current have this line of code in MyPlayerController's code:

    MyPawn(Pawn).Foo();


    But this line of code ends up calling MyPlayerPawn's version of Foo() not MyPawn's version of Foo(). I want it to call MyPawn's version.

    What syntax do I use to get it to call MyPawn's version of the function?


    Thanks!

    #2
    I don't think your going to get this working, only by using what the UCC error says.

    You could set it up like this.

    Code:
    class MyPawn extends Pawn;
    function Foo(Bool inVal)
    { ... }  // MyPawn.Foo() ignores the inVal.
    
    class MyPlayerPawn extends MyPawn;
    function WhatEver()
    {
          Foo(True);
          Foo(False);
    }
    function Foo(Bool inVal)
    { 
           if (inVal)
             Super.Foo(inVal);    // Execute MyPawn.Foo code
          else
            ...........           // Execute MyPlayerPawn.Foo code
    }
    And to call from your controller class:
    Code:
    function DoFoo()
    {
           if (MyPlayerPawn(Pawn)!=none) {
                  MyPlayerPawn(Pawn).Foo(True);  // Call MyPawn.Foo()
                  MyPlayerPawn(Pawn).Foo(False); // Call MyPlayerPawn.Foo()
           }
    }
    This I have not tested.

    Comment


      #3
      er, yeah, thats a long way, heh.

      Super(MyPawn).foo() should do it. It will also call the pawn version, if MyPawn.foo happens to call super as well.

      The call to super can be used to call any function from the any super class, you can skip 1, or 5, or 3000.

      Comment


        #4
        Super(MyPawn).Foo() doesn't specify the which Pawn reference I'm calling Foo() for.

        Remember this code statement is issued from inside the Controller's code not the MyPlayerPawn's code. If it were, that line would correct.

        'Pawn' is the variable name declared inside of class Controller in Controller.uc.

        MyPlayerPawn(Pawn).Foo(); // this calls MyPlayerPawn's version of Foo()
        MyPawn(Pawn).Foo(); // this calls the same function as the line above (I think in C++ casting to the parent type would call the MyPawn version of Foo())


        Here is why Super(MyPawn).Foo() doesn't work inside of the Controller's code.

        Once is Foo() called, Foo() needs to know what Pawn's actual data to use. i.e. Location, Rotation values. So I have to give variable name has to be part of the code statement.

        This is why: Super(MyPawn).Foo() troubles me that it even compiles because Foo() uses Location as part of it's function. Where is that data being pulled from. :weird:

        Comment

        Working...
        X