Jump to content

Tearing my hair out... trying to create a formlist[] array and AddForm() isn't working


Recommended Posts

I'm trying to put together a hotkey mod, partly because none of the ones I've seen do precisely what I want, and partly because I like to punish my brain with activities I have no aptitude for*.

 

I'm using a bunch of parallel arrays to keep track of various things. Things like dual-cast flags are stored in a string array and scancodes are in an int array. I planned to create a Formlist array to store the spells/weapons/whatever the player attaches to a particular hotkey. An example might be helpful. Say the player wants to bind Y to cast Stoneflesh on both hands, followed by Fireball on the left hand and then equip Ice Spike on the right hand:

 

hotkeys[0] will be 21, the scancode for the Y key

hotkeyOptions[0] will be CDCLER (Cast Dual/Cast Left/Equip Right)

hotkeyItems[0] will be a formlist containing Stoneflesh, Fireball, and Ice Spike

 

The second hotkey would be stored in hotkey*[1], the third in hotkey*[2] and so on.

 

The int array hotkeys[] and the string array hotkeyOptions[] are working perfectly. I've spent days getting them synchronised, and I was really happy with what I added. Then I added this little line of code:

 

HotkeyItems.AddForm(item)

 

...and my life fell apart

 

The item variable is supposed to be whatever the player selects. I'm planning to use an MCM menu option to get the FormID to add to the formlist. The MCM is all working fine. Problem is, whatever I do, HotkeyItems[] just stays as None, None, None, None, None... ad infinitum. I can't add anything to the list. The script compiles ok, and everything seems to be going fine, but the formlists stay empty. Needless to say, the ability to equip such things as spells and weapons is an integral feature of the mod.

 

Code extracts:

 

 

 

Scriptname COCOMenuScript extends SKI_ConfigBase
{Menu script for Complete Control}

MiscObject Property COCODummyMenuNew Auto

Event OnInit()
    parent.onInit()

    ;init arrays
    HotKeys = new int[64]
    HotkeyOptions = new string[64]
    HotkeyItems = new formlist[64]
EndEvent

Event OnOptionSelect(int option)
    if option == NewHotkeyOID
        AddHotkey()
        ForcePageReset()
    endIf
endEvent

function AddHotkey()
    int i = HotkeyOptions.Find("", 0)  ;find the first empty slot in the arrays
    HotkeyOptions[i] = "0RE0.0"  ;write default hotkey options (fully listed, right hand, equip only, no delay)
    HotkeyItems[i].AddForm(COCODummyMenuNew) ;add dummy form to list
    return
endFunction

 

 

If the rest of the script is necessary for context, please shout and I'll post it. But I think I've extracted everything that might be relevant.

 

I'm filling the property in the CK (triple checked that). Completely out of ideas. I'm on the verge of scrapping the whole project which Wouldn't Be A Good Thing because I'd have to take up reading, or ice skating or something.

 

*Seriously, no aptitude whatsoever. Ask my university. They suggested suicide, or burger king.

Link to comment
Share on other sites

Thankyou Seven. Unfortunately that isn't working. HotkeyItems[] stays empty.

 

I added a wee bit of debug code:

        Debug.TraceUser("COCODebugLog", "AddHotkey() is adding a new hotkey to index " + i)
        HotkeyOptions[i] = "0RE0.0"  ;write default hotkey options (fully listed, right hand, equip only, no delay)
        formlist list = HotkeyItems[i]
        Debug.Traceuser("COCODebugLog", "list = " + list)
        list.AddForm(COCODummyMenuNew)
        Debug.Traceuser("COCODebugLog", "list = " + list)
        HotkeyItems[i] = list  ;add dummy form to list
        Debug.TraceUser("COCODebugLog", "HotkeyItems[" + i + "] = " + HotkeyItems[i])

list isn't getting populated at all:

 

[05/08/2015 - 04:47:43AM] AddHotkey() is adding a new hotkey to index 0
[05/08/2015 - 04:47:43AM] list = None
[05/08/2015 - 04:47:43AM] list = None
[05/08/2015 - 04:47:43AM] HotkeyItems[0] = None

 

Puzzling.

Link to comment
Share on other sites

Ah, I bet since formlist isn't a primitive type every cell in the HotkeyItems array is initialized to 'None'. So somehow you're going to have to get formlist instances and then add them to the array before you can then add forms to each formlist. Unfortunately, I think the only way to create FormList instances is to autofill them as properties in the CK.

 

What still puzzles me is how Papyrus manages to execute what effectively evaluates to None.AddForm(COCODummyMenuNew) with no error.

Link to comment
Share on other sites

Your Array needs to be populated before attempting to make changes. Also not sure if this applies in this case, but arrays can only be one dimensional, and FormLists my be functionally similar to an array (Don't know if it works that way or not so go ahead and try populating the array before trying the hot key logic again)
Link to comment
Share on other sites

I gave up in the end. Rather than trying to give each hotkey its own formlist, I've created a form[] array that will hold all the forms. Another, parallel array holds indices into the form[] array for each hotkey. It's not ideal, but at least it works. Thanks for all your help guys.

Link to comment
Share on other sites

I use formlists in place of arrays in one case because of the ability to make formlists of formlists. It's the closest you can get to multi-dimensional arrays in Skyrim. The only trick is that you have to type every single item within a formlist when you reference it.

 

Instead of this:

HotkeyItems[i].AddForm(item)

This:

(HotkeyItems[i] As FormList).AddForm(item)
Link to comment
Share on other sites

  • Recently Browsing   0 members

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