Object oriented multi-dimensional arrays

Post » Mon Nov 19, 2012 9:07 am

I've asked quite a few questions on this forum so I figured I'd share some info. This is an idea McGuffin came up with when helping me make my code more manageable. I'm not entirely sure about the impact on resources but it is a great idea worth a look.

My hotkey's mod has arrays within arrays within arrays and lots of them. Basically there is a set of master arrays that line up. They store your keypress (two arrays for two corresponding keys), info about the key you press (stored as multiplied prime numbers and accessed using the % command returning 0), and the object linked to the key. That object can be a cycle with multiple objects so each cycle is another set of arrays. Within a cycle or master array can be sets which is another set of arrays storing multiple items. As you can see this can become a lot of code fast. Especially without knowing how to append variables in papyrus.

So here was the solution. My master arrays are kept in the script. Then I created a miscobject for cycles and attached a script that handles its arrays. For the amount of cycles I wanted I dragged the miscobject into an empty cell to create an instance of it. I added these cycles to a form list. Now by storing the instanced cycle in the master arrays reference I can pull it up and retrieve info from it. Basically using this code:

Int[] CycleTagForm[] CycleFInt CycleCountint c = 0While c < MHP_cycleslist.GetSize()  If CycleForm == MHP_cycleslist.GetAt(c)	CycleF = (MHP_cycleslist.GetAt(c) as MHP_CyclesScript).CycleF	CycleTag = (MHP_cycleslist.GetAt(c) as MHP_CyclesScript).CycleTag	CycleCount = (MHP_cycleslist.GetAt(c) as MHP_CyclesScript).CycleCount	index = c	c = MHP_cycleslist.GetSize()  endif  c += 1endwhile

I did the same thing for sets.

This was a great idea IMO by McGuffin. And really prevented my code from being a cluster. While also allowing me to add endless amounts of cycles/sets as easy as drag an drop. It also greatly speed up the process to check through all the arrays.
User avatar
Greg Cavaliere
 
Posts: 3514
Joined: Thu Nov 01, 2007 6:31 am

Return to V - Skyrim