Announcement

Collapse
No announcement yet.

access allactors from an interaction?

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

    access allactors from an interaction?

    Hi

    Im an artist (in the traditional sense of the word).
    My past work involved using UT's AI to draw portraits (link to pics)

    Im doing my best to understand Unrealscript but my head is literally throbbing trying to fix a problem, any help would be greatly appreciated!

    Heres what I got, I followed a tutorial that created a mutator and an interaction class. (the mutator , the interaction)

    At the moment when you press a particular key (like x) it will right "you pressed x" in the log file.
    What I want to happen is when you press (say x) the code will find movers with the tag "move 1" and make them move.

    Code:
    Class keyinteract_inter extends Interaction;
    
    Function Initialize()
    {
        Log("Interaction Initialized");
    
    }
    
    
    function bool KeyEvent(EInputKey Key, EInputAction Action, FLOAT Delta )
    {
    
    
       local Mover M;
    
        if ((Action == IST_Press) && (Key == IK_F)) 
        {
            Log("you pressed F");
    
           foreach AllActors(class'Mover', M, move1)
          {
          Log("I at the very least found a mover with that tag");
          }
       }
    
    
        return false;
    }
    
    
    DefaultProperties
    {
         bActive=True
    }
    I read somewhere that "The AllActors function is defined in the Actor class, so classes that aren't in that branch of the class tree can't use ForEach"

    what should I do?

    #2
    ViewportOwner.Actor in Interaction is a PlayerController, you can use that as reference actor. E.g.
    Code:
    foreach ViewportOwner.Actor.AllActors(class'Mover', M, move1)

    Comment


      #3
      Thank you for the suggestion!

      unfortunately I still get a compiler error saying: call to "allactors" bad expression or missing
      with the following code

      Code:
         local Mover M;
      
          if ((Action == IST_Press) && (Key == IK_F)) 
          {
              Log("you pressed F");
      
            foreach ViewportOwner.Actor.AllActors(class'Mover', M, move1)
            {
            Log("I at the very least found a mover with that tag");
            }
         }

      Comment


        #4
        What is that "move1" in there?

        Comment


          #5
          its supposed to be the tag? i think

          I got this off the wiki...
          AllActors (class<Actor> BaseClass, out Actor Actor, optional name MatchTag)
          If you specify an optional MatchTag, only includes actors which have a "Tag" variable specified

          I only want the code to find a specific mover, this mover has the tag "move1"

          Comment


            #6
            If you want to hard-code the tag name, you need to write it as a name literal, i.e. enclose the value in single quotes.

            Comment


              #7
              wow!

              your a star!

              I can now press a key and the relevant mover will be found, I get a lovely message in my log file saying "mover 2 found"

              thank you.

              Now for the second part of the conundrum, how do I make my mover... move.
              it has 2 key frames 'key 0' and 'key 1'.

              i attempted this
              Code:
                 local Mover M;
              
                  if ((Action == IST_Press) && (Key == IK_F)) 
                  {
                    Log("you pressed F");
              
                    foreach ViewportOwner.Actor.AllActors(class'Mover', M, 'move1')
                    {
                    Log("mover 1 found");
                    M.GotoState('key 1');
                    }
              
                  }
              It compiled but caused errors in the log file.
              any ideas?

              Comment


                #8
                My guess is you want to call Triggered() on the relevant actors. (he says, posting without being able to refer to the source, again)

                Comment


                  #9
                  Thanks, Ive been looking at the whole trigger thing but am having major difficulties.

                  Im not even sure I should have the code as it is.
                  There is a console command called: Causeevent <eventname>

                  and thats exactly what I need, I just need to cause an event, the event will move my mover.

                  Code:
                      if ((Action == IST_Press) && (Key == IK_F)) 
                      {
                          Log("you pressed F");
                          //CAUSEEVENT move1?
                     }
                  this code is probably closer to what I want?
                  Is it possible to turn a console command into something that will work here?

                  Comment


                    #10
                    I think maybe what you are looking for is this function in Actor:

                    Code:
                    simulated event TriggerEvent( Name EventName, Actor Other, Pawn EventInstigator )
                    {
                    	local Actor A;
                    	local NavigationPoint N;
                    
                    	if ( EventName == '' )
                    		return;
                    
                    	ForEach DynamicActors( class 'Actor', A, EventName )
                    		A.Trigger(Other, EventInstigator);
                    
                    	For ( N=Level.NavigationPointList; N!=None; N=N.NextNavigationPoint )
                    		if ( N.bStatic && N.Tag == EventName )
                    			N.Trigger(Other, EventInstigator);
                    }

                    Comment


                      #11
                      Thank you! but Im sorry it just dosnt work.

                      Or at least it dosnt work how I tryed it. I just dont understand a word of it. I dont know how to fit it in.

                      Is there no simple way of causing an event to happen from within an interaction class?
                      Im getting so desperate now Ive started looking at macro editors that will automatically bring the console down and type in "causeevent move1" based on a specific keypress.

                      (only problem with that is the macros cause UT to crash!)
                      deary me, my poor little movers arent fulfilling their potential.

                      Comment


                        #12
                        A quick 101:

                        you already know that when you cause an event, every actor with the tag matching the event name will be triggered.

                        What you probably haven't realised is that all that happens when you cause an event is that something steps through all the actors just like your loop does, compares event name with tag and calls Triggered() on the actor if it matches.

                        ffejnosliw posted the function that actors use to cause an event. I'd guess that this is exactly the code that happens when you CAUSEEVENT at the console.

                        The reason you have the problem is that Interaction is not an actor, so it doesn't have AllActors, nor does it have TriggerEvent.

                        My suggestion would be to have the playercontroller run the TriggerEvent, thus:

                        Code:
                            if ((Action == IST_Press) && (Key == IK_F)) 
                            {
                              Log("you pressed F, triggering an event");
                              ViewportOwner.Actor.TriggerEvent('move 1',ViewportOwner.Actor,None);
                            }
                        hope that works, I haven't tried it.

                        Comment


                          #13
                          thank you all! a million times over!

                          Thanks NakedApe, for showing me the viewport thingy!
                          Thanks Wormbo for seeing the error with the ' ' !
                          Thanks ffejnosliw for showing me the relevant trigger code!
                          Thanks Sweavo for explaining it and showing me how to impliment it!

                          thank you thank you!
                          (needless to say it is now all working!)

                          Comment

                          Working...
                          X