I'm trying to create a simple LeveledForm data structure that can contain more than 128 entries. It just keeps track of an SKSE form array and a SKSE int array, and resizes them whenever necessary.
I wrote a new script that inherits from Form, and it compiled successfully. I can now successfully compile other scripts that use a LeveledForm object. But in-game any references to LeveledForms result in Papyrus errors:
Scriptname LeveledForm extends Form
;Data
Form[] form_array
Int[] level_array
;Capacity
int cap = 128
;Current number of entries
int num = 0
;===Initialization===
event OnInit()
Debug.Notification("Creating LeveledForm")
form_array = Utility.CreateFormArray(cap)
level_array = Utility.CreateIntArray(cap)
endEvent
;===Insertion===
int function AddEntry(Form new_form, int new_level)
Debug.Notification("Adding " + new_form.GetName() + ", lv." + new_level)
int i = num
; If there is no free space, double array cap
if (i >= cap)
Form[] old_formArray = form_array
Int[] old_levelArray = level_array
form_array = Utility.CreateFormArray(cap*2)
level_array = Utility.CreateIntArray(cap*2)
int j = cap
while (j > 0)
j -= 1
form_array[j] = old_FormArray[j]
level_array[j] = old_LevelArray[j]
endWhile
cap = cap*2
endif
; Save the new data
form_array[i] = new_form
level_array[i] = new_level
num = num + 1
return i
Debug.Notification("New form has been added.")
endFunction
;===Retrieval===
int function GetSize()
return num
endFunction
Form function GetAt(int i)
return form_array[i]
endFunction
int function GetLevelAt(int i)
return level_array[i]
endFunction
The calls to Debug.Notification() aren't printing anything, presumably because my LeveledForm objects are never successfully instantiated.
Any idea what I might be doing wrong?