Jump to content

[SCRIPTING] Actor Array


Deleted11438360User

Recommended Posts

Okay, I sometimes have a two or more NPCs, so I created an array for them to make management easier.

;Not full code

Actor[] Property Actors Auto

Elseif (aiButton == 5)
      If (Actors != none)  
          Actors.MoveTo(XMarker) ; Obviously this won't compile which is my question.
      Else
         ;No actors
      Endif

So I know I doing it wrong, because I obviously can't move the whole array of actors at once. How do I get around this? I won't have to create individual new Actor properties will I?

 

If you can give a script example I would be grateful, as I just want to know the most optimised and best way around this. I thought I was done last time, but I want to make everything easier - as I may want to expand the file in the future.

 

Thank you again.

Edited by Guest
Link to comment
Share on other sites

You need to iterate the array, the actors are elements. If you do not need the Else statement, you can replace the whole If-Else-EndIf with a While loop. I am not sure if you can directly use the array index thingy, but the following method compiled, at least (not tested):

Actor[] Property Actors Auto
ObjectReference Property XMarker Auto

Elseif (aiButton == 5)
    Int iTemp = Actors.Length
    While(iTemp > 0)
        iTemp -= 1
        Actors[iTemp].MoveTo(XMarker)
    EndWhile
Link to comment
Share on other sites

No problem. I did not manage to see your post before you edited it, but if you have any questions, feel free to ask. Good luck with your project. :smile:

 

Edit: in case that does not work in-game, if Papyrus did not like using array elements like that (cannot remember at the moment), you can try this, it is the same, but with the actor "extraction" thingy done before using it:

Int iTemp = Actors.Length
Actor rTemp = None
While(iTemp > 0)
    rTemp = Actors[iTemp]
    If(rTemp)
        rTemp.MoveTo(XMarker)
    EndIf
EndWhile
Edited by Contrathetix
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...