CreateStringArray - need some help please.

Post » Thu Oct 13, 2016 9:51 pm

Hey all, hoping I could get a bit of help please..



I need to create an array but need the index to change dynamically. so eg.





string[] sNPCNamesFoundArray

...

...

sNPCNamesFoundArray = new String [x]

...

where 'x' is needs to change based on other values within the game/script, but according to vanilla programing, it can't accept variables and needs a literal number.

but, skse has a way to do just that using this function:



"

String[] http://www.creationkit.com/index.php?title=CreateStringArray_-_Utility&action=edit&redlink=1(Int size, String fill = "")
  • Creates and returns a String array with length size, with each element initialized to fill.

  • Be careful when using this function. It is possible to create arrays longer than 128 elements, and size is treated as an unsigned integer. Negative numbers will produce extremely large values, which can cause major issues."


i just have no idea how to use that. If I could see a real use scenario script in how CreateStringArray works, then I can figure it out and incorporate it within my own scripts.



PS: the array will be used in a listbox, used from SkyUTil which lists npc's for the player to choose from. but that list changes all the time and i need the array to reflect the change. everything works so far, but when using literal values, the list also produces spaces in the list box because the array index is filled with blanks but contains no NPC names. the list doesn't care if there are no strings, it just cares about how long the index array total is. hence why i need an array to change the index on the fly if needed.



eg..currently, i have a space for an 80 index array.. that's the max, in the list box it'll show



[ NPC name ]


[ ]


[ ]


[ NPC name ]


..


etc.. till all 80 from the array are shown.


with a dynamic array, i can have the array size the same as however many npc's it finds. i'd check my other array, if an index is used, tick a counter on it, when a counter gets to the end, add it up, then create the new array using the counter number. done and done. would take me 2 seconds to do.



TLDR; http://www.creationkit.com/index.php?title=CreateStringArray_-_Utility&action=edit&redlink=1 , need to know how to use this function in psuedo script. please.



thanks,



CS - T-Mush-S



User avatar
Shelby McDonald
 
Posts: 3497
Joined: Sat Jan 13, 2007 2:29 pm

Post » Fri Oct 14, 2016 2:57 am

You're overthinking it. It's just a function which returns an array. The simple case is:
sNPCNamesFoundArray = CreateStringArray(x)
And that replaces the "sNPCNamesFoundArray = new String [x]" line.
User avatar
Sunnii Bebiieh
 
Posts: 3454
Joined: Wed Apr 11, 2007 7:57 pm

Post » Thu Oct 13, 2016 5:14 pm

oh, yeah that does make it simple.. hah.. thanks. :)

User avatar
leni
 
Posts: 3461
Joined: Tue Jul 17, 2007 3:58 pm


Return to V - Skyrim