ResizeIntArray - Utility: Difference between revisions
Jump to navigation
Jump to search
→Examples
| Line 22: | Line 22: | ||
<source lang="papyrus"> | <source lang="papyrus"> | ||
; let's make array length equal to available perk points, and fill all elements with 9 | ; let's make array length equal to available perk points, and fill all elements with 9 | ||
; ...this should really be using the "create" function, not "resize" | |||
int[] pointsArray | int[] pointsArray | ||
pointsArray = Utility.ResizeIntArray(pointsArray, Game.GetPerkPoints(), 9) | pointsArray = Utility.ResizeIntArray(pointsArray, Game.GetPerkPoints(), 9) | ||
; Let's resize an existing array, someArray, expanding it by one element. The fill value (in this case, not specified so the default of zero) will be used for new elements (in this case, the last one) and all other element values will remain the same as they were before being resized. | |||
someArray = Utility.ResizeIntArray(someArray, someArray.Length + 1) | |||
; Let's resize an existing array, someArray, by making it one element shorter. The removed element, would be the last one in the array. The data in all other elements should be unchanged. | |||
; NOTE 1: this is not "safe" code, it could theoretically try to Resize the array to zero length (if it's currently 1) which Resize will not allow, resulting in an error in the papyrus log. Use "Create" versions if you need to shrink an existing array to zero elements. | |||
; NOTE 2: The autofill value is meaningless and ignored when shrinking an array. | |||
someArray = Utility.ResizeIntArray(someArray, someArray.Length - 1) | |||
</source> | </source> | ||