Editing
ResizeIntArray - Utility
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
[[Category:Scripting]] [[Category:Papyrus]] '''SKSE member of:''' [[Utility Script]] Resizes an already existing array of Int values to the specified length. (This function requires SKSE)<br> '''Be careful when using this function.''' It is possible to create arrays longer than 128 elements, and size is treated as an unsigned 32-bit integer. Do not exceed a length of 2^31. SKSE's DLL can handle a max length of 2^32 '''however, Papyrus cannot.''' Negative numbers will produce extremely large values, which can cause major issues. == Syntax == <syntaxhighlight lang="papyrus"> int[] Function ResizeIntArray(int[] source, int size, int fill = 0) global native </syntaxhighlight> == Parameters == * source: an existing array of int values. * size: new size of the array. * fill: a value to fill empty elements of the array with, if the array being resized is longer than the source array. == Return Value == An Int array of '''''size''''' length. Element values will match those provided by the source array. If new size (array.length) exceeds size of source array, new elements will will have the value of the fill (if specified) or zero if not. == Examples == <syntaxhighlight lang="papyrus"> ; 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 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) </syntaxhighlight> == Notes == * No need to actually create an array with '''''new''''', declaring an array variable is enough. However, be sure to "Create" or "Resize" the array before trying to read/set any element values in it, or you will get an error for trying to access an uninitialized array. == See Also == *[[Utility Script]]
Summary:
Please note that all contributions to the CreationKit Wiki are considered to be released under the Creative Commons Attribution-ShareAlike (see
CreationKit:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
Edit source
View history
More
Search
Navigation
Landing page
Tutorials
Game Systems
Editor Reference
Scripting Reference
Recent changes
Help
Tools
What links here
Related changes
Special pages
Page information
Page values