Announcement

Collapse
No announcement yet.

cantget controller from pawn......

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

    cantget controller from pawn......

    I create my pedPawns in my custom GameType. In my pawn class i spawn its pedAIController. Everything works, Im very happy about that, but when I try to access the controller from the gametype i get errors... I pasted some code to further explain.

    in pedPawn class (extends xPawn):
    event PreBeginPlay()
    {
    Super.PreBeginPlay();

    Controller = Spawn(class'pedEvac.pedAIController');
    Controller.Possess(self);
    Controller.GotoState('Idle');
    log("Spawning " $ Controller $ " for " $ self.Name, 'in Prebegin');

    }
    function pedEvac.pedAIController getController()
    {
    return Controller;
    }

    then in my game type i got:
    pedBot[1].getController();

    any idea whats going on? how can i get my custom pawns controller?
    thanks in advance...

    #2
    Re: cantget controller from pawn......

    Originally posted by keyser_sose

    function pedEvac.pedAIController getController()
    {
    return Controller;
    }
    For the return type try pedAiController instead.

    So:
    Code:
    function pedAiController getController() {
      return Controller;
    }

    Comment


      #3
      Yeah i tried that first and it said type mismatch. I dont get it, I clearly spawn the Controller of pedAIController.... what is the deal???

      Comment


        #4
        Have you tried typecasting the return type?

        Code:
        function pedAiController getController() {
           return pedAiController(Controller);
        }
        It is possibly saying its a type mismatch because Controller may or may not be of type pedAiController (even though you destinctyly set it to that).

        I found in extending xDeathmatch's spawnbot function when I attempted to use a variable in the line:
        Code:
        NewBot = Bot(Spawn(myControllerVar));
        it needed the Bot() typecast, yet when I changed this to
        Code:
        NewBot = Spawn(Class'myBot');
        I no longer needed to typecast, in fact I got a compiler error saying it is unneccesary. So what im trying to say here is that using a variable as you are with Controller it wanted a typecast.

        Also I hate the use of variable names which are also data types/classes in Uscript. It may well be thinking its return type is pedAiController and your actually returning a Controller type, of course a parent is not a type of the child. i.e. a pedAiController is a Controller but a Controller is not a pedAiController.

        Actually would that function not be more accurate/useful if its return type was Controller instead of pedAiController? That way it would let you know if it is a pedAiController or a xBot controller or any other sort of controller.

        Code:
        function Controller getController()
        {
            return Controller;
        }

        Comment


          #5
          Thats because return Controller returns a type Controller, not a type pedAiController. Controller is a Controller type. Therefor, you have to cast as you return. return pedAiController(Controller);

          Comment


            #6
            good looking out guys...
            i tried typecasting but i was using java convention and it didnt work, ill try this out tho.
            thanks again.

            Comment

            Working...
            X