Jump to content

[LE] Help with Arrays pls :D !


Recommended Posts

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 vars

int Var1

int Var2

int Var3

int Var4

...

...

 

  Reveal hidden contents

 

 

 

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 Arrays

writing 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 by TobiaszPL
Link to comment
Share on other sites

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 by foamyesque
Link to comment
Share on other sites

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 = 0
EndFunction
;-----------------------
Link to comment
Share on other sites

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

  Reveal hidden contents

 

Link to comment
Share on other sites

and finally the init function for the script from above.. keep in mind papyrus has a limit of 128 elements

 

 

  Reveal hidden contents

 

Link to comment
Share on other sites

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

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

  Reveal hidden contents

 

Link to comment
Share on other sites

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 trick
Now 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 maze
concept 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 ...

  Reveal hidden contents


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, tomahto
Not sure what your over all point was in this post. But if it was to poke at me, writing the
exact 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 my
my 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 by NexusComa
Link to comment
Share on other sites

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 by ReDragon2013
Link to comment
Share on other sites

"any1 know any good tutorial about arrays?

to this moment i was using insane amount of normal vars

int Var1

int Var2

int Var3

int Var4

int Var5

int Var6

int var7

int var8

int var9

int var10

int var11

int var12

int var13

int var14

int var15

int var15

int var16

int var17

int var18

int var19

int var20

int var21

int var22

int var23

int var24

int var25

int var26

int var27

int var28

int var29

int var30

int var31

int var32

int var33

int var34

int var35

int var36

int var37

int var38

int var39

int var40

int var41

int var42

int var43

int var44

int var45

int var46

int var47

int var48

int var49

int var50

int var51

int var52

int var53

int var54

int var55

int var56

int var57

int var58

int var59

int var60

int var61

int var62

int var63

int var64

int var65

int var66

int var67

int var68

int 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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...