TobiaszPL Posted March 14, 2019 Share Posted March 14, 2019 (edited) i found this:https://www.creationkit.com/index.php?title=Arrays_(Papyrus) and now im reading it cause i need Arrays T_T any1 know any good tutorial about arrays?to this moment i was using insane amount of normal varsint Var1int Var2int Var3int Var4...... int Var5int Var6int var7int var8int var9int var10int var11int var12int var13int var14int var15int var15int var16int var17int var18int var19int var20int var21int var22int var23int var24int var25int var26int var27int var28int var29int var30int var31int var32int var33int var34int var35int var36int var37int var38int var39int var40int var41int var42int var43int var44int var45int var46int var47int var48int var49int var50int var51int var52int var53int var54int var55int var56int var57int var58int var59int var60int var61int var62int var63int var64int var65int var66int var67int var68int var69 ahh 69 <3 xD N++ help a lot so u can do it in less than 1 min :tongue: its not bad way to do it but scripts are getting really long with this way and i have few questions :c 1) do i have to delete Array or CK is doing it for me??? 2) can i use FormList to fill array?a) how if i can? 3) Global can be Array? 4) it is possible to kill CK/Game with TO BIG arrays?for example array with 7000 elements? 5) What functions i have to use for arrays? y i know my english is bad i mean do CK have something like Array.Clear()Array.SizeOf()Array.Fill()Array.Swap() y i know i can try everything by myself but i want to know everything :tongue:and idk how i can check memory use by my mods in CK :c im gonna start new Script to control Arena Waves so i need Arrayswriting 1000 variables isn't hard but FILLING it with data... omfg Maybe example script with Arrays ? :smile:this what is on CK Wiki is... pretty poor :c i already fill 120 variables once and... i dont want to do it anymore xD //Edit:Array Max size is rly 128 ? O_O Edited March 14, 2019 by TobiaszPL Link to comment Share on other sites More sharing options...
foamyesque Posted March 14, 2019 Share Posted March 14, 2019 (edited) Okay, so, a few things: 1. Arrays are not, by themselves, a form in Papyrus, which means you've got only the hardcoded functions listed on the wiki available in the ArrayName.Function() format. 2. Arrays are pointers to the memory reserved for their elements. That means that if you do, say, ArrayA = ArrayB, they become the same array; any changes made to ArrayB after that will immediately show up in ArrayA. 3. The vast majority of what you want to do with arrays involves manipulating array elements. You see a lot of structures like this: int i = ArrayA.Length while i > 0 i-=1 ;do something to each ArrayA[i] element endwhile It can be used for evaluating each element against certain conditions, copying it to another array, setting each element to a given value, etc. 4. The default limit in scripting 128, yes. You can extend past that either by having a second array and writing some wrapper functions to manage them (this is clunky but avoids SKSE reliance) or by using SKSE, which, for certain basic classes of array -- Form, Alias, and the primitives int, string, float, and bool -- will allow you to create arrays of any size, and unlike the vanilla scripting, do so with variables instead of hardcoded literals. I don't know what happens if you try to put >128 items into a property array through the CK instead of scripting; I've never tried. 5. There's an SKSE function for a FormList, ToArray(), https://www.creationkit.com/index.php?title=FormList_Script That will output a Form[] array version of the FormList it is called on. Otherwise you need to iterate through the formlist manually copying each element into your target array. 6. Any kind of variable at all can be made an array, including GlobalVariables (since GlobalVariables are, strictly, a kind of Form, and Forms can be arrays). In general I prefer to use the most basic type, for access to the SKSE functions, and cast the elements where necessary. 7. Unreferenced arrays are automatically garbage collected. You don't need to manually undeclare or clear them. Edited March 14, 2019 by foamyesque Link to comment Share on other sites More sharing options...
NexusComa Posted March 15, 2019 Share Posted March 15, 2019 Not sure if this helps. Made this a few years back. Worked well for me at getting around the 128 array limit thing.This one is for Objects but you could use it for any type of array.Int oC = 0 ;objs ; cell/object (counter)Event OnInit();--- cache definitions o1 =(New ObjectReference[128]) o2 =(New ObjectReference[128]) o3 =(New ObjectReference[128]) o4 =(New ObjectReference[128]) o5 =(New ObjectReference[128]) o6 =(New ObjectReference[128]) o7 =(New ObjectReference[128])EndEvent;-----------------------Function CellCache(ObjectReference Obj) If(oC<(128)) o1[oC]=(Obj) ElseIf(oC<(256)) o2[oC-(128)]=(Obj) ElseIf(oC<(384)) o3[oC-(256)]=(Obj) ElseIf(oC<(512)) o4[oC-(384)]=(Obj) ElseIf(oC<(640)) o5[oC-(512)]=(Obj) ElseIf(oC<(768)) o6[oC-(640)]=(Obj) ElseIf(oC<(896)) o7[oC-(768)]=(Obj) EndIf oC+=(1)EndFunction ;-----------------------Function ClearCache() Int r0=(0) ;--- r0=(o1.length) While(r0) r0-=(1) If(o1[r0]) o1[r0].Delete() o1[r0]=(None) EndIf EndWhile r0=(o2.length) While(r0) r0-=(1) If(o2[r0]) o2[r0].Delete() o2[r0]=(None) EndIf EndWhile r0=(o3.length) While(r0) r0-=(1) If(o3[r0]) o3[r0].Delete() o3[r0]=(None) EndIf EndWhile r0=(o4.length) While(r0) r0-=(1) If(o4[r0]) o4[r0].Delete() o4[r0]=(None) EndIf EndWhile r0=(o5.length) While(r0) r0-=(1) If(o5[r0]) o5[r0].Delete() o5[r0]=(None) EndIf EndWhile r0=(o6.length) While(r0) r0-=(1) If(o6[r0]) o6[r0].Delete() o6[r0]=(None) EndIf EndWhile r0=(o7.length) While(r0) r0-=(1) If(o7[r0]) o7[r0].Delete() o7[r0]=(None) EndIf EndWhile Utility.Wait(1.0) oC = 0EndFunction;----------------------- Link to comment Share on other sites More sharing options...
ReDragon2013 Posted March 19, 2019 Share Posted March 19, 2019 the architecture of arrays is a bit different to normal variables in papyrus. Best way use a hidden script with your own array functions.Next is a sample script for form[] arrays. Probably something can be better. ArrayGlobalForm Scriptname ArrayGlobalForm Hidden {written by ReDragon 2017} ; modders resource for extended arrays ; How to call the global functions from other scripts? ; --------------------------------------------------- ; "i" have to be a number between 1 and 128 ; Form[] newFormArray = ArrayGlobalForm.Init(i) ; ArrayGlobalForm.Clear(a) ; ArrayGlobalForm.Add(a, fm) ; Bool ; ArrayGlobalForm.Remove(a, fm) ; Bool ; ArrayGlobalForm.Sort(a) ; ArrayGlobalForm.CountAll(a) ; Int ; ArrayGlobalForm.Count(a, fm) ; Int ; ArrayGlobalForm.HasEntry(a, fm) ; Bool ; ArrayGlobalForm.FindFirst(a, fm) ; Int ; ArrayGlobalForm.FindLast(a, fm) ; Int ; ArrayGlobalForm.SwapArray(a, b) ; ArrayGlobalForm.FillArrayAt(a, fm, iStart) ; Bool ; ArrayGlobalForm.RemoveBadElements(a, bSort) ; Bool ; ArrayGlobalForm.WalkArray(a) ; -- FUNCTIONs -- 14 ;--------------------------- FUNCTION WalkArray(Form[] a) Global ;--------------------------- Debug.Trace("<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>") Debug.Trace("<> form WALK - START - <>") Debug.Trace("<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>") int iMax = a.Length int i = 0 WHILE (i < iMax) Debug.Trace("-----> Index " +i+ ": " +a[i]) i = i + 1 ENDWHILE Debug.Trace("<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>") Debug.Trace("<> form WALK = END = <>") Debug.Trace("<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>") ENDFUNCTION ;---------------------------------------------------------- Bool FUNCTION RemoveBadElements(Form[] a, Bool bSort=TRUE) Global ;---------------------------------------------------------- ; TRUE = Success ; False = (bad formID not found) ; http://forums.bethsoft.com/topic/1413790-resource-beyond-128-extended-array-functions-to-go-to-512-and-up/ ; Try to remove every element with bad formID from array ; Optional: do not sort the array after success! int iMax = a.Length int c = 0 int i = 0 WHILE (i < iMax) IF (a[i] as String == "[Form <None>]") ;;; form fm = a[i] ;;; IF (fm) && (((fm as String) as Int) == 0) a[i] = None ; overwrite array element by native <None>Form c = c + 1 ENDIF i = i + 1 ENDWHILE IF (c == 0) Return False ; /1 all array elements have valid entries (which can be <None>) ENDIF ;--------- IF ( bSort ) Sort(a) ; optional: sort the array after remove ENDIF Return TRUE ; /2 ENDFUNCTION ;---------------------------------------------------------- Bool FUNCTION FillArrayAt(Form[] a, Form fm, Int iStart=0) Global ;---------------------------------------------------------- ; TRUE = Success, array was filled at start position up to end with specific form ; False = bad start position IF (iStart < 0) || (iStart > 127) Debug.Trace("ArrayGlobalForm: FillArrayAt() - Error: Wrong start position! (0..127) is " +iStart) Return False ; /1 ENDIF ;========= int iMax = a.Length int i = iStart WHILE (i < iMax) a[i] = fm i = i + 1 ENDWHILE Return TRUE ; /2 ENDFUNCTION ;------------------------------------- FUNCTION SwapArray(Form[] a, Form[] b) Global ;------------------------------------- int n = b.Length int iMax = a.Length IF (iMax == 0) Debug.Trace("ArrayGlobalForm: SwapArray() - Error: source array is unassigned!") RETURN ; - STOP - ENDIF ;--------------------- IF (n == 0) Debug.Trace("ArrayGlobalForm: SwapArray() - Error: destination array is unassigned!") RETURN ; - STOP - ENDIF ;--------------------- IF (iMax == n) ELSE Debug.Trace("ArrayGlobalForm: SwapArray() - Warning: arrays are of different length!") ENDIF int i = 0 WHILE (i < iMax) && (i < n) b[i] = a[i] ; write array element from source "a" into destination "b" i = i + 1 ENDWHILE ENDFUNCTION ;---------------------------------------- Int FUNCTION FindLast(Form[] a, Form fm) Global ;---------------------------------------- ; returns = last position of specific form, <None> also available ; -1 = fm not found within the array ; Requires Skyrim v1.6 ; int Function RFind(;/element type/; akElement, int aiStartIndex = -1) native IF ( fm ) RETURN a.RFind(fm) ; /1 ENDIF int i = a.Length WHILE (i > 0) i = i - 1 IF (a[i] == fm) RETURN i ; /2 ENDIF ENDWHILE RETURN -1 ; /3 ENDFUNCTION ;----------------------------------------- Int FUNCTION FindFirst(Form[] a, Form fm) Global ;----------------------------------------- ; returns = first position of specific form, <None> also available ; -1 = fm not found within the array ; Requires Skyrim v1.6 ; int Function Find(;/element type/; akElement, int aiStartIndex = 0) native IF ( fm ) RETURN a.Find(fm) ; /1 ENDIF int iMax = a.Length int i = 0 WHILE (i < iMax) IF (a[i] == fm) RETURN i ; /2 ENDIF i = i + 1 ENDWHILE RETURN -1 ; /3 ENDFUNCTION ;----------------------------------------- Bool FUNCTION HasEntry(Form[] a, Form fm) Global ;----------------------------------------- ; TRUE = specific form was found, <None> also available ; False = fm not found within the array int iMax = a.Length int i = 0 WHILE (i < iMax) IF (a[i] == fm) Return TRUE ENDIF i = i + 1 ENDWHILE Return False ENDFUNCTION ;------------------------------------- Int FUNCTION Count(Form[] a, Form fm) Global ;------------------------------------- ; returns = number of array elements which have the specified form, counts also <None> ; 0 = fm not found within the array int iMax = a.Length int c = 0 ; counter int i = 0 WHILE (i < iMax) IF (a[i] == fm) c = c + 1 ; increment counter by 1 ENDIF i = i + 1 ENDWHILE RETURN c ENDFUNCTION ;------------------------------- Int FUNCTION CountAll(Form[] a) Global ;------------------------------- ; returns = number of array elements which are not <None> ; 0 = array is empty int iMax = a.Length int c = 0 ; counter int i = 0 WHILE (i < iMax) IF a[i] c = c + 1 ; increment counter by 1 ENDIF i = i + 1 ENDWHILE RETURN c ENDFUNCTION ;---------------------- FUNCTION Sort(Form[] a) Global ;---------------------- ; non-recursive sorting, first part are valid formIDs, the second part has <None> entries int iMax = a.Length int n = -1 ; init by -1 int i = 0 ; start with a[0] WHILE (i < iMax) form fm = a[i] IF (n == -1) IF ( fm ) ELSE n = i ; set first position of <None> element, do it once only ENDIF ELSEIF ( fm ) ; current array element has a valid FormID a[n] = fm ; shift current element down to position of first <None> element fm = None a[i] = fm ; set current element to None, which becomes the upper boundary for next loop WHILE (a[n]) && (n < i) n = n + 1 ; increment by 1, until we found the next None element in this array ENDWHILE ENDIF i = i + 1 ENDWHILE ENDFUNCTION ;-------------------------------------------------------- Bool FUNCTION Remove(Form[] a, Form fm, Bool bSort=TRUE) Global ;-------------------------------------------------------- ; TRUE = Success ; False = Error: fm not found or <None> ; Overwrites the first matching form (fm as parameter) by <None> IF ( fm ) ELSE Return False ; /1 <None> ENDIF ;--------- int i = a.Find(fm) IF (i < 0) Return False ; /2 form not found ENDIF ;--------- a[i] = None IF ( bSort ) Sort(a) ENDIF Return TRUE ; /3 ENDFUNCTION ;------------------------------------ Bool FUNCTION Add(Form[] a, Form fm) Global ;------------------------------------ ; TRUE = Success ; False = Error: array full or <None> ; Adds a form (fm as parameter) to the first array element of <None> IF ( fm ) ELSE Return False ; /1 <None> ENDIF ;--------- int iMax = a.Length int i = 0 WHILE (i < iMax) IF a[i] ELSE a[i] = fm Return TRUE ; /2 ok! ENDIF i = i + 1 ENDWHILE Return False ; /3 array is full ENDFUNCTION ;----------------------- FUNCTION Clear(Form[] a) Global ;----------------------- form[] b ; declare a temporary stack array of same type, unassigned a = b ; clear the array to None ENDFUNCTION Link to comment Share on other sites More sharing options...
ReDragon2013 Posted March 19, 2019 Share Posted March 19, 2019 and finally the init function for the script from above.. keep in mind papyrus has a limit of 128 elements ;--------------------------- Form[] FUNCTION Init(Int i) Global ;--------------------------- ; Skyrim papyrus compiler cannot handle that: a = new Form[i] ; i < 1, we take 1 ; i > 128, we take 128 form[] a IF (i < 60) IF (i < 20) a = myF_00_10(a, i) RETURN a ENDIF ; ---------- IF (i < 40) a = myF_20_30(a, i) RETURN a ENDIF ; ---------- a = myF_40_50(a, i) RETURN a ENDIF ;============= IF (i < 100) IF (i < 80) a = myF_60_70(a, i) RETURN a ENDIF ; ---------- a = myF_80_90(a, i) RETURN a ENDIF ;============= IF (i < 120) a = myF_100_110(a, i) RETURN a ENDIF ; ---------- a = myF_120(a, i) RETURN a ENDFUNCTION ;----------------------------------------- Form[] FUNCTION myF_00_10(Form[] a, Int i) Global ; 1..9, 10..19 ;----------------------------------------- IF (i < 7) IF (i <= 1) ; do not allow Zero or negative values a = new Form[1] RETURN a ENDIF ; ---------- IF (i == 2) a = new Form[2] RETURN a ENDIF ; ---------- IF (i == 3) a = new Form[3] RETURN a ENDIF ; ---------- IF (i == 4) a = new Form[4] RETURN a ENDIF ; --------- IF (i == 5) a = new Form[5] RETURN a ENDIF ; ---------- a = new Form[6] RETURN a ENDIF ;============= IF (i < 12) IF (i == 7) a = new Form[7] RETURN a ENDIF ; ---------- IF (i == 8) a = new Form[8] RETURN a ENDIF ; ---------- IF (i == 9) a = new Form[9] RETURN a ENDIF ; ---------- IF (i == 10) a = new Form[10] RETURN a ENDIF ; ---------- a = new Form[11] RETURN a ENDIF ;============= IF (i < 16) IF (i == 12) a = new Form[12] RETURN a ENDIF ; ---------- IF (i == 13) a = new Form[13] RETURN a ENDIF ; ---------- IF (i == 14) a = new Form[14] RETURN a ENDIF ; ---------- a = new Form[15] RETURN a ENDIF ;============= IF (i == 16) a = new Form[16] RETURN a ENDIF ; ---------- IF (i == 17) a = new Form[17] RETURN a ENDIF ; ---------- IF (i == 18) a = new Form[18] RETURN a ENDIF ; ---------- a = new Form[19] RETURN a ENDFUNCTION ;----------------------------------------- Form[] FUNCTION myF_20_30(Form[] a, Int i) Global ; 20..29, 30..39 ;----------------------------------------- IF (i < 26) IF (i == 20) a = new Form[20] RETURN a ENDIF ; ---------- IF (i == 21) a = new Form[21] RETURN a ENDIF ; ---------- IF (i == 22) a = new Form[22] RETURN a ENDIF ; ---------- IF (i == 23) a = new Form[23] RETURN a ENDIF ; --------- IF (i == 24) a = new Form[24] RETURN a ENDIF ; ---------- a = new Form[25] RETURN a ENDIF ;============= IF (i < 31) IF (i == 26) a = new Form[26] RETURN a ENDIF ; ---------- IF (i == 27) a = new Form[27] RETURN a ENDIF ; ---------- IF (i == 28) a = new Form[28] RETURN a ENDIF ; ---------- IF (i == 29) a = new Form[29] RETURN a ENDIF ; ---------- a = new Form[30] RETURN a ENDIF ;============= IF (i < 35) IF (i == 31) a = new Form[31] RETURN a ENDIF ; ---------- IF (i == 32) a = new Form[32] RETURN a ENDIF ; ---------- IF (i == 33) a = new Form[33] RETURN a ENDIF ; ---------- a = new Form[34] RETURN a ENDIF ;============= IF (i < 38) IF (i == 35) a = new Form[35] RETURN a ENDIF ; ---------- IF (i == 36) a = new Form[36] RETURN a ENDIF ; ---------- a = new Form[37] RETURN a ENDIF ;============= IF (i == 38) a = new Form[38] RETURN a ENDIF ; ---------- a = new Form[39] RETURN a ENDFUNCTION ;----------------------------------------- Form[] FUNCTION myF_40_50(Form[] a, Int i) Global ; 40..49, 50..59 ;----------------------------------------- IF (i < 46) IF (i == 40) a = new Form[40] RETURN a ENDIF ; ---------- IF (i == 41) a = new Form[41] RETURN a ENDIF ; ---------- IF (i == 42) a = new Form[42] RETURN a ENDIF ; ---------- IF (i == 43) a = new Form[43] RETURN a ENDIF ; --------- IF (i == 44) a = new Form[44] RETURN a ENDIF ; ---------- a = new Form[45] RETURN a ENDIF ;============= IF (i < 51) IF (i == 46) a = new Form[46] RETURN a ENDIF ; ---------- IF (i == 47) a = new Form[47] RETURN a ENDIF ; ---------- IF (i == 48) a = new Form[48] RETURN a ENDIF ; ---------- IF (i == 49) a = new Form[49] RETURN a ENDIF ; ---------- a = new Form[50] RETURN a ENDIF ;============= IF (i < 55) IF (i == 51) a = new Form[51] RETURN a ENDIF ; ---------- IF (i == 52) a = new Form[52] RETURN a ENDIF ; ---------- IF (i == 53) a = new Form[53] RETURN a ENDIF ; ---------- a = new Form[54] RETURN a ENDIF ;============= IF (i < 58) IF (i == 55) a = new Form[55] RETURN a ENDIF ; ---------- IF (i == 56) a = new Form[56] RETURN a ENDIF ; ---------- a = new Form[57] RETURN a ENDIF ;============= IF (i == 58) a = new Form[58] RETURN a ENDIF ; ---------- a = new Form[59] RETURN a ENDFUNCTION ;----------------------------------------- Form[] FUNCTION myF_60_70(Form[] a, Int i) Global ; 60..69, 70..79 ;----------------------------------------- IF (i < 66) IF (i == 60) a = new Form[60] RETURN a ENDIF ; ---------- IF (i == 61) a = new Form[61] RETURN a ENDIF ; ---------- IF (i == 62) a = new Form[62] RETURN a ENDIF ; ---------- IF (i == 63) a = new Form[63] RETURN a ENDIF ; --------- IF (i == 64) a = new Form[64] RETURN a ENDIF ; ---------- a = new Form[65] RETURN a ENDIF ;============= IF (i < 71) IF (i == 66) a = new Form[66] RETURN a ENDIF ; ---------- IF (i == 67) a = new Form[67] RETURN a ENDIF ; ---------- IF (i == 68) a = new Form[68] RETURN a ENDIF ; ---------- IF (i == 69) a = new Form[69] RETURN a ENDIF ; ---------- a = new Form[70] RETURN a ENDIF ;============= IF (i < 75) IF (i == 71) a = new Form[71] RETURN a ENDIF ; ---------- IF (i == 72) a = new Form[72] RETURN a ENDIF ; ---------- IF (i == 73) a = new Form[73] RETURN a ENDIF ; ---------- a = new Form[74] RETURN a ENDIF ;============= IF (i < 78) IF (i == 75) a = new Form[75] RETURN a ENDIF ; ---------- IF (i == 76) a = new Form[76] RETURN a ENDIF ; ---------- a = new Form[77] RETURN a ENDIF ;============= IF (i == 78) a = new Form[78] RETURN a ENDIF ; ---------- a = new Form[79] RETURN a ENDFUNCTION ;----------------------------------------- Form[] FUNCTION myF_80_90(Form[] a, Int i) Global ; 80..89, 90..99 ;----------------------------------------- IF (i < 86) IF (i == 80) a = new Form[80] RETURN a ENDIF ; ---------- IF (i == 81) a = new Form[81] RETURN a ENDIF ; ---------- IF (i == 82) a = new Form[82] RETURN a ENDIF ; ---------- IF (i == 83) a = new Form[83] RETURN a ENDIF ; --------- IF (i == 84) a = new Form[84] RETURN a ENDIF ; ---------- a = new Form[85] RETURN a ENDIF ;============= IF (i < 91) IF (i == 86) a = new Form[86] RETURN a ENDIF ; ---------- IF (i == 87) a = new Form[87] RETURN a ENDIF ; ---------- IF (i == 88) a = new Form[88] RETURN a ENDIF ; ---------- IF (i == 89) a = new Form[89] RETURN a ENDIF ; ---------- a = new Form[90] RETURN a ENDIF ;============= IF (i < 95) IF (i == 91) a = new Form[91] RETURN a ENDIF ; ---------- IF (i == 92) a = new Form[92] RETURN a ENDIF ; ---------- IF (i == 93) a = new Form[93] RETURN a ENDIF ; ---------- a = new Form[94] RETURN a ENDIF ;============= IF (i < 98) IF (i == 95) a = new Form[95] RETURN a ENDIF ; ---------- IF (i == 96) a = new Form[96] RETURN a ENDIF ; ---------- a = new Form[97] RETURN a ENDIF ;============= IF (i == 98) a = new Form[98] RETURN a ENDIF ; ---------- a = new Form[99] RETURN a ENDFUNCTION ;------------------------------------------- Form[] FUNCTION myF_100_110(Form[] a, Int i) Global ; 100..109, 110..119 ;------------------------------------------- IF (i < 106) IF (i == 100) a = new Form[100] RETURN a ENDIF ; ---------- IF (i == 101) a = new Form[101] RETURN a ENDIF ; ---------- IF (i == 102) a = new Form[102] RETURN a ENDIF ; ---------- IF (i == 103) a = new Form[103] RETURN a ENDIF ; --------- IF (i == 104) a = new Form[104] RETURN a ENDIF ; ---------- a = new Form[105] RETURN a ENDIF ;============= IF (i < 111) IF (i == 106) a = new Form[106] RETURN a ENDIF ; ---------- IF (i == 107) a = new Form[107] RETURN a ENDIF ; ---------- IF (i == 108) a = new Form[108] RETURN a ENDIF ; ---------- IF (i == 109) a = new Form[109] RETURN a ENDIF ; ---------- a = new Form[110] RETURN a ENDIF ;============= IF (i < 115) IF (i == 111) a = new Form[111] RETURN a ENDIF ; ---------- IF (i == 112) a = new Form[112] RETURN a ENDIF ; ---------- IF (i == 113) a = new Form[113] RETURN a ENDIF ; ---------- a = new Form[114] RETURN a ENDIF ;============= IF (i < 118) IF (i == 115) a = new Form[115] RETURN a ENDIF ; ---------- IF (i == 116) a = new Form[116] RETURN a ENDIF ; ---------- a = new Form[117] RETURN a ENDIF ;============= IF (i == 118) a = new Form[118] RETURN a ENDIF ; ---------- a = new Form[119] RETURN a ENDFUNCTION ;--------------------------------------- Form[] FUNCTION myF_120(Form[] a, Int i) Global ; 120..128 ;--------------------------------------- IF (i < 124) IF (i == 120) a = new Form[120] RETURN a ENDIF ; ---------- IF (i == 121) a = new Form[121] RETURN a ENDIF ; ---------- IF (i == 122) a = new Form[122] RETURN a ENDIF ; ---------- a = new Form[123] RETURN a ENDIF ;============= IF (i < 127) IF (i == 124) a = new Form[124] RETURN a ENDIF ; ---------- IF (i == 125) a = new Form[125] RETURN a ENDIF ; ---------- a = new Form[126] RETURN a ENDIF ;============= IF (i == 127) a = new Form[127] RETURN a ENDIF ; ---------- a = new Form[128] ; do now allow values greater than 128 RETURN a ENDFUNCTION Link to comment Share on other sites More sharing options...
NexusComa Posted March 20, 2019 Share Posted March 20, 2019 That's pretty cool and pretty complicated. The snip I showed above was used in a script for a random dungeon.I needed to keep track of a lot of newly spawned objects and be able to reset everything on the fly to create a new random dungeon.Took a few years to figure out and it works really well. A true maze generator. Someday .... if I ever finish that home I'll post it.Hostilely isn't looking good at this point. But I may pull the random dungeon part out and post it solo at some point. Link to comment Share on other sites More sharing options...
ReDragon2013 Posted March 21, 2019 Share Posted March 21, 2019 NexusComa wrote: "The snip I showed above was used in a script for .. Took a few years to figure out and it works really well." Well .. next code is what I would do: xtArrayObjScript Scriptname xtArrayObjScript extends Quest ObjectReference[] o0 ; 0.. 127 ObjectReference[] o1 ; 128.. 255 ObjectReference[] o2 ; 256.. 383 ObjectReference[] o3 ; 384.. 511 ObjectReference[] o4 ; 512.. 639 ObjectReference[] o5 ; 640.. 767 ObjectReference[] o6 ; 768.. 895 ObjectReference[] o7 ; 896..1023 Int oCounter ; extended array position counter ; -- EVENT -- EVENT OnInit() oCounter = 0 o0 = new ObjectReference[128] o1 = new ObjectReference[128] o2 = new ObjectReference[128] o3 = new ObjectReference[128] o4 = new ObjectReference[128] o5 = new ObjectReference[128] o6 = new ObjectReference[128] o7 = new ObjectReference[128] ENDEVENT ; -- FUNCTIONs -- 4 ;-------------------------------------------- FUNCTION myF_Add(Int i, ObjectReference oRef) ; internal helper ;-------------------------------------------- int p = 0 ; single array position within extended array WHILE (i > 128) p = p + 1 i = i - 128 ENDWHILE IF (p == 0) o0[i] = oRef RETURN ; - STOP - ENDIF ;--------------------- IF (p == 1) o1[i] = oRef RETURN ; - STOP - ENDIF ;--------------------- IF (p == 2) o3[i] = oRef RETURN ; - STOP - ENDIF ;--------------------- IF (p == 3) o3[i] = oRef RETURN ; - STOP - ENDIF ;--------------------- IF (p == 4) o4[i] = oRef RETURN ; - STOP - ENDIF ;--------------------- IF (p == 5) o5[i] = oRef RETURN ; - STOP - ENDIF ;--------------------- IF (p == 6) o6[i] = oRef RETURN ; - STOP - ENDIF ;--------------------- ;IF (p == 7) o7[i] = oRef ; RETURN ; - STOP - ;ENDIF ;;--------------------- ENDFUNCTION ;---------------------------------------- FUNCTION AddToCache(ObjectReference oRef) ;---------------------------------------- int i = oCounter IF (i >= 1023) RETURN ; - STOP - overflow ENDIF ;--------------------- IF (i < 0) RETURN ; - STOP - underflow ENDIF ;--------------------- myF_Add(i, oRef) oCounter += 1 ENDFUNCTION ;------------------------------------------- FUNCTION myF_Del(Int i, ObjectReference[] a) ; internal helper ;------------------------------------------- IF (i * 128 > oCounter) RETURN ; - STOP - counter exceeds ENDIF ;--------------------- i = a.Length WHILE (i) ; (i > 0) i = i - 1 objectReference oRef = a[i] IF ( oRef ) ; (oRef != None) oRef.Delete() oRef = None a[i] = oRef ENDIF ENDWHILE ENDFUNCTION ;-------------------- FUNCTION ClearCache() ;-------------------- myF_Del(1, o0) myF_Del(2, o1) myF_Del(3, o2) myF_Del(4, o3) myF_Del(5, o4) myF_Del(6, o5) myF_Del(7, o6) myF_Del(8, o7) ;;; Utility.Wait(1.0) oCounter = 0 ENDFUNCTION Link to comment Share on other sites More sharing options...
NexusComa Posted March 22, 2019 Share Posted March 22, 2019 (edited) Well I meant the entire mod. The random dungeon took a few weekends.That > snip < is part of a 45k script. That part took about 5 min to make ...Like I said from the snip pile. The concept on how to by-pass the limit was the point.the finish code has the While loop on the clears though not as complex as yours is.At this point in the design i was still pondering different size arrays. Later I just went with the full 128. You basically wrote the same code with a While and use of Return vs ElseIf.What's up with that ?? ... I was hoping to see you covert this concept into your forms trickNow that would have been impressive and worth the read! I do like how you combined two steps on the set up and auto hidden, Basinga! To be fair working was all I was looking for at that point. I couldn't wait to implement the mazeconcept and that was the part I meant was working really will. Thanks for the pointer.I was just happy I figured out a way to do more arrays that really works.Thought maybe this might help him out. But I did forget to post the top part ... Full Snip ...ObjectReference[] Property o1 Auto Hidden ;* object cachesObjectReference[] Property o2 Auto Hidden ; 128 * 7 = 896 (895 max)ObjectReference[] Property o3 Auto HiddenObjectReference[] Property o4 Auto HiddenObjectReference[] Property o5 Auto HiddenObjectReference[] Property o6 Auto HiddenObjectReference[] Property o7 Auto HiddenInt oC = 0 ;objs ; cell/object (counter)Int[] o1 ;*ref ;Int[] o2 ;*refInt[] o3 ;*refInt[] o4 ;*refInt[] o5 ;*refInt[] o6 ;*refInt[] o7 ;*refEvent OnInit() ;--- cache definitions o1 =(New ObjectReference[128]) o2 =(New ObjectReference[128]) o3 =(New ObjectReference[128]) o4 =(New ObjectReference[128]) o5 =(New ObjectReference[128]) o6 =(New ObjectReference[128]) o7 =(New ObjectReference[128])EndEvent;-----------------------Function CellCache(ObjectReference Obj) If(oC<(128)) o1[oC]=(Obj) ElseIf(oC<(256)) o2[oC-(128)]=(Obj) ElseIf(oC<(384)) o3[oC-(256)]=(Obj) ElseIf(oC<(512)) o4[oC-(384)]=(Obj) ElseIf(oC<(640)) o5[oC-(512)]=(Obj) ElseIf(oC<(768)) o6[oC-(640)]=(Obj) ElseIf(oC<(896)) o7[oC-(768)]=(Obj) EndIf oC+=(1)EndFunction;-----------------------Function ClearCache() Int r0=(0) ;--- r0=(128) While(r0) r0-=(1) If(o1[r0]) o1[r0].Delete() o1[r0]=(None) o2[r0].Delete() o2[r0]=(None) o3[r0].Delete() o3[r0]=(None) o4[r0].Delete() o4[r0]=(None) o5[r0].Delete() o5[r0]=(None) o6[r0].Delete() o6[r0]=(None) o7[r0].Delete() o7[r0]=(None) EndIf EndWhile oC = 0EndFunction;-----------------------Beautiful tight and completely understandable at a glance ... even 9 years later ...You are calling the p as a number that matches the object number 0 = o0[], 1 = o1[].If only there was a way to work that in so you could just call the array in one line.I was looking at this at first but actually like how Elseif's turned out ...Pretty much self rem'ed.Again you wrote the same code with a different twist on the math and format ... tomayto, tomahtoNot sure what your over all point was in this post. But if it was to poke at me, writing theexact same code in a slightly different format isn't much of a dig, honestly ...Programming is easy ... designing viable programming concepts defines your skill level.Love your work on that forms list and I wasn't poking fun of anything. However, I do try to keep mymy codes and code segments as readable as possible always looking for that one page glance tell all.Especially when someone having problems understanding the subject (arrays) in the first place.That how I end up posting snips (pre-design) and not the actual finished polished code.But everyone has their own style I guess. Again I meant no harm ... Edited March 22, 2019 by NexusComa Link to comment Share on other sites More sharing options...
ReDragon2013 Posted March 22, 2019 Share Posted March 22, 2019 (edited) The headline of this thread was "Help with Arrays". Nothing more..You provided a script snippet which is forming some single arrays to a (big) extended array. My approach which I posted was not intended to show anyone here "How to make an extended array script",it should give advise to use array functions by using a hidden script with predefined global functions, not more! Two years ago I wrote my own extended array script (like Chesko mod), which this script is using that I posted here as spoiler. Edited March 22, 2019 by ReDragon2013 Link to comment Share on other sites More sharing options...
NexusComa Posted March 22, 2019 Share Posted March 22, 2019 "any1 know any good tutorial about arrays?to this moment i was using insane amount of normal varsint Var1int Var2int Var3int Var4int Var5int Var6int var7int var8int var9int var10int var11int var12int var13int var14int var15int var15int var16int var17int var18int var19int var20int var21int var22int var23int var24int var25int var26int var27int var28int var29int var30int var31int var32int var33int var34int var35int var36int var37int var38int var39int var40int var41int var42int var43int var44int var45int var46int var47int var48int var49int var50int var51int var52int var53int var54int var55int var56int var57int var58int var59int var60int var61int var62int var63int var64int var65int var66int var67int var68int var69"This can be modified to handle as many arrays as he needs in any format. And shows Array usages deeply.While helping him get rid of all them definitions in a row ... how is that not helpful? Link to comment Share on other sites More sharing options...
Recommended Posts