Jump to content

Understanding dynamic array correctly


SMB92

Recommended Posts

  On 5/24/2017 at 8:46 AM, kitcat81 said:

You don`t needÃÂ to keepÃÂ anyone as a variableÃÂ unless you areÃÂ going to run some other functions on them later. And youÃÂ needÃÂ ÃÂ toÃÂ run the function onÃÂ eachÃÂ spawned actor ( because you can have more than 1 spawned actors, ).ÃÂ Just a question, why doÃÂ ÃÂ youÃÂ need a linked ref?ÃÂ Actors usually have a default package to stay near editor location. ( the location where they were spawned in this case)

ÃÂ  While SpawnCounter > 0
ÃÂ  ÃÂ  ÃÂ  ÃÂ  ÃÂ ÃÂ  IfÃÂ  ; your  conditions for spawningÃÂ  here
ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ  ActorÃÂ  MyActor = Self.PlaceActorAtMe(your  data here, but the quantity  should be 1)ÃÂ  
ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ  MyActor.DeleteWhenAble() ; mark the actor  as temporary so the game deletes him when the cell is detached
ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ  EndIf
           SpawnCounter = SpawnCounter - 1 ; doing this outside the "if" block  allows to shorten the script
  EndWhile
I link them to a patrol marker dynamically and they start patrolling the network of markers I have in place. Some spawns that I don't want to patrol will not have this code. Reason why I have made this network is that it is strongly noted by users of WOTC patrol AI was broken at some point. I was hoping that doing this would ensure it worked well always, and provided a patrol marker network other modders could use as well.

 

And yes, I will probably want to run other functions later on, it will definitely be handy.

 

Thanks for the optimization there too

Link to comment
Share on other sites

  • Replies 111
  • Created
  • Last Reply

Top Posters In This Topic

  On 5/24/2017 at 9:09 AM, SMB92 said:

And yes, I will probably want to run other functions later on, it will definitely be handy.

 

Thanks for the optimization there too

 

I link them to a patrol marker dynamically and they start patrolling the network of markers I have in place. Some spawns that I don't want to patrol will not have this code. Reason why I have made this network is that it is strongly noted by users of WOTC patrol AI was broken at some point. I was hoping that doing this would ensure it worked well always, and provided a patrol marker network other modders could use as well.

Not al all. Just note that setting linked ref creates persistence. And keeping/storing actors as variables makes them persistent too. You can`t delete a persistent ref while something keeps it persistent. It will get "D" flag (deleted) and it might become invisible, but it will be still be there untill you clear the variable or remove something that keeps it in the world.

Edited by kitcat81
Link to comment
Share on other sites

  On 5/24/2017 at 9:21 AM, kitcat81 said:

 

  On 5/24/2017 at 9:09 AM, SMB92 said:

And yes, I will probably want to run other functions later on, it will definitely be handy.

 

Thanks for the optimization there too

 I link them to a patrol marker dynamically and they start patrolling the network of markers I have in place. Some spawns that I don't want to patrol will not have this code. Reason why I have made this network is that it is strongly noted by users of WOTC patrol AI was broken at some point. I was hoping that doing this would ensure it worked well always, and provided a patrol marker network other modders could use as well.

Not al all. Just note that setting linked ref creates persistence. And keeping/storing actors as variables makes them persistent too. You can`t delete a persistent ref while something keeps it persistent. It will get "D" flag (deleted) and it might become invisible, but it will be still be there untill you clear  the variable or remove something that keeps it in the world.

Ah very good! I'll unlink them as well, I would of missed that :P

Link to comment
Share on other sites

Okay so learned the hard way Add() and Remove() no work on these arrays lol.

 

Anyway this is the new script (compiled) for anyone interested:

 

 

  Reveal hidden contents

 

Link to comment
Share on other sites

  On 5/24/2017 at 12:00 PM, kitcat81 said:

Add and remove do work for arrays. May be  it does not work for a reference, I did not try that, but it works for a form for sure.Â

Compiler carried on it wasn't a known function lol. So I done it like how you see above.

Â

I'm glad you mentioned the SetLinkedRef thing, because this Array is not working properly. It's not setting the LinkedRef to None. It's saying the Index is out of range in papyrus logs as well. Perhaps I should be declaring it as an array property, maybe it's not saving at the end of the function.Â

 

Edit - maybe because I have declared it at a size of 0. Maybe i should declare it at the max spawn size first, and use the groupmember int to get where its actually filled to. That kind seems like its not a dynamic array though to me. Name of topic lol.

Link to comment
Share on other sites

  On 5/24/2017 at 12:21 PM, SMB92 said:

 

  On 5/24/2017 at 12:00 PM, kitcat81 said:

Add and remove doà work for arrays.à May beà à it does not work for a reference, I did not try that, but ità works for aà form for sure.Ã

Compiler carried on it wasn't a known function lol. So I done it like how you see above.

Ã

I'm glad you mentioned the SetLinkedRef thing, because this Array is not working properly. It's not setting the LinkedRef to None. It's saying the Index is out of range in papyrus logs as well. Perhaps I should be declaring it as an array property, maybe it's not saving at the end of the function.Ã

 

Edit - maybe because I have declared it at a size of 0. Maybe i should declare it at the max spawn size first, and use the groupmember int to get where its actually filled to. That kind seems like its not a dynamic array though to me. Name of topic lol.

 

I think the way you were addressing the arrays for add/remove was incorrect which was giving you problems. Your last posting with your updated script for adding entries to the array is possibly the better solution. I'm not sure of the performance impact of using Add on an array vs pre-defining the size and directly addressing the index. If you know ahead of time pre-defining might make the script a little faster. But Add will work regardless and in cases where you need to redefine the size. Though the removal could be done a few different ways. Here's some options.

 

This sample code isn't complete as it's missing quite a few variable definitions. But using the same naming as your script it should be pretty easy to follow. Did I mention I tend to write more comment than code.

 

  Reveal hidden contents

 

 

Your original code

 

 

  Reveal hidden contents

 

 

Your use of SpawnList[GroupMembers].Add(Spawn as Actor) is incorrect. You never defined anything that would match to SpawnList[GroupMembers]. The Add function needs the base array, in this case SpawnList. It adds to the end so GroupMembers is irrelevant here. You would do the entire add loop and then at the end of the loop set GroupMembers = SpawnList.Length. Though you could get the length at any time that way without needing the additional variable. The removal in your OP is workable if you specify the index to remove. array.Remove() is invalid. array.Remove(0) removes the first index. You can also use array.RemoveLast() which takes off the last entry.

Edited by BigAndFlabby
Link to comment
Share on other sites

Wow, this looks complex. I haven't started learning coding for FO4 yet. But this looks like a variation of C.

In most programming languages I know, if you declare a private variable, it will vanish along with the function once function finishes its operation? So instead of creating a global variable that lingers, why not creating a custom variable type and pass this array around like parameters between functions. Too many global variables can increase memory load, and if not cleaning properly can cause problems.

Link to comment
Share on other sites

  On 5/25/2017 at 1:21 AM, tomomi1922 said:

Wow, this looks complex. I haven't started learning coding for FO4 yet. But this looks like a variation of C.

 

In most programming languages I know, if you declare a private variable, it will vanish along with the function once function finishes its operation? So instead of creating a global variable that lingers, why not creating a custom variable type and pass this array around like parameters between functions. Too many global variables can increase memory load, and if not cleaning properly can cause problems.

Yeah I generally dislike using Globals if possible. But in Papyrus GlobalVariable is something actually global to the game not the script. So it's a little different context. Then you have "local script variables" which are global to any functions in the script. Then there's local function variables. Which are exactly as it sounds.

 

I was bored so I took the last piece of code and did some refactoring to make it a bit smaller. This is the refactored code. Also grouped the properties. If we wanted to get more advanced you could define a struct then pass an array of the struct then have the script loop the array of struct to decide what to spawn rather than having to hard code each type individually. The changes to the script aren't all that complex but having to re-input everything in the plugin would be tedious. The benefit to do this would be that adding additional spawn types later would be as easy as just setting the variables in CK. No script changes needed since it pulls it all from the vars.

 

I'd also like to point out that the code originally (and still) uses the same lvl list to spawn both regular and boss actors. For future use you'd probably want to add additional boss lists.

 

I also converted all the properties to const. This way if the plugin was ever updated the values would pass to the script. Otherwise when the script first fires and starts running it saves all those values inside the save file. If it's attached to a quest then it would never terminate and restart unless the quest was stopped and then restarted.

 

 

  Reveal hidden contents

 

 

This is as much of the original code in tact with the refactor and the redundant stuff commented out for reference. I did group the properties though.

 

  Reveal hidden contents

 

Edited by BigAndFlabby
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...