I've got a rather complex script set up, and unsurprisingly, it's not working. However, it's failing at a point I wouldn't have expected. First, the goal: I'm trying to create a framework, mostly just as an exercise. The framework is supposed to make it so mods can communicate and pass forms to one another without having to rely on the other mod being present or anything. Only one mod would need this script; the rest of the mods would just have a single form which would do nothing on its own, but would serve the purpose of passing information to a mod should it be present without any hassle.
Example: ModA charges the player money for their houses (MatthiasWagg's new mod is what made me think of this). It wants to charge different prices for different houses. But how can a ModB's house's price be determined? The best way is for ModB's author to set it in his mod. But where can he do this? Most ways he goes requires him to parent and patch ModA, or use GetFormFromFile to patch it, or to have ModA's author add ModB. One way it could work is as follows:
- ModB creates a GlobalVariable with the house's price.
- ModB's GlobalVariable's FormID is changed using Tes5Edit to {ModIndex}{F}{ModA'sNexusID}.
- ModA scans all plugins and checks if the form {ModIndex}{F}{ModA'sNexusID} exists. If so, it stores ModIndex (in an array) and the form (in a FormList).
As long as ModA is set up with this system to pull in this information, any other mod may add to this by creating one form (the global variable), setting its value (in this case, leave it at 0 until the player owns the house, then set it to the appropriate number), and ModA can find that number and use it without the two mods (or even the authors) ever having to do any real work for it.
The problem: Here's the chunk of code:
Form CurrentForm = Game.GetForm(CurrentFormID)If CurrentForm ModIDs[CurrentModIndex] = CurrentFormID Forms.AddForm(CurrentForm) Debug.MessageBox("Current Form: " + CurrentForm + ", Forms: " + Forms.GetAt(0)) CurrentModIndex += 1EndIf
The issue is that even though the debug message appears (telling me CurrentForm is NOT empty), and the message shows "Current Form:
Scriptname X99_PCF_ManagerScript extends QuestInt[] Property ModIDs Auto HiddenFormList Property Forms Auto HiddenGlobalVariable Property X99_PCF_GL_DoOnce AutoEvent OnInit() RegisterForSingleUpdate(0.1)EndEventEvent OnUpdate() If X99_PCF_GL_DoOnce.GetValue() X99_PCF_GL_DoOnce.SetValue(0) ModIDs = New Int[128] Int CurrentModIndex = 0 Int Mods = Game.GetModCount() While Mods Mods -= 1 Int CurrentFormID = HexToTen(TenToHex(Mods)+"F57239") Form CurrentForm = Game.GetForm(CurrentFormID) If CurrentForm ModIDs[CurrentModIndex] = CurrentFormID Forms.AddForm(CurrentForm)Debug.MessageBox("Current Form: " + CurrentForm + ", Forms: " + Forms.GetAt(0)) CurrentModIndex += 1 EndIf EndWhile While CurrentModIndex;Debug.MessageBox("CurrentModIndex: " + CurrentModIndex) CurrentModIndex -= 1 If Forms.GetAt(CurrentModIndex) as GlobalVariable Debug.Notification(CurrentModIndex + ": " + ModIDs[CurrentModIndex] + ", " + (Forms.GetAt(CurrentModIndex) as GlobalVariable).GetValue()) ElseIf Forms.GetAt(CurrentModIndex) as FormList Int i = 0 While ( i < (Forms.GetAt(CurrentModIndex) as FormList).GetSize() ) Debug.Notification(CurrentModIndex + ": " + ModIDs[CurrentModIndex] + ", " + i + ": " +((Forms.GetAt(CurrentModIndex) as FormList).GetAt(i) as GlobalVariable).GetValue() ) i += 1 EndWhile EndIf EndWhile EndIfEndEventString Function TenToHex(Int InputTTH) Int Power = -1 Bool Found = False Int HexLength String SoFar While (Found == False) Power += 1 If ( InputTTH < Math.POW(16, Power) ) HexLength = Power Found = True EndIf EndWhile Int LengthDone = 0 Int Current = InputTTH Int ModCurrent = Current%16 String CurrentHex While ( LengthDone < HexLength ) If (ModCurrent == 1) CurrentHex = "1" ElseIf (ModCurrent == 2) CurrentHex = "2" ElseIf (ModCurrent == 3) CurrentHex = "3" ElseIf (ModCurrent == 4) CurrentHex = "4" ElseIf (ModCurrent == 5) CurrentHex = "5" ElseIf (ModCurrent == 6) CurrentHex = "6" ElseIf (ModCurrent == 7) CurrentHex = "7" ElseIf (ModCurrent == 8) CurrentHex = "8" ElseIf (ModCurrent == 9) CurrentHex = "9" ElseIf (ModCurrent == 10) CurrentHex = "A" ElseIf (ModCurrent == 11) CurrentHex = "B" ElseIf (ModCurrent == 12) CurrentHex = "C" ElseIf (ModCurrent == 13) CurrentHex = "D" ElseIf (ModCurrent == 14) CurrentHex = "E" ElseIf (ModCurrent == 15) CurrentHex = "F" Else CurrentHex= "0" EndIf SoFar = CurrentHex+SoFar LengthDone += 1 If ( LengthDone < HexLength ) Current = (Current-ModCurrent)/16 EndIf EndWhile Return SoFarEndFunctionInt Function HexToTen(String InputHTT) Int Length2 = StringUtil.GetLength(InputHTT) Int LengthDone2 = 0 Int SoFar2 = 0 While ( LengthDone2 < Length2 ) String CurrentDigit = StringUtil.GetNthChar(InputHTT, LengthDone2) Int CurrentTen If (CurrentDigit == "1") CurrentTen = 1 ElseIf (CurrentDigit == "2") CurrentTen = 2 ElseIf (CurrentDigit == "3") CurrentTen = 3 ElseIf (CurrentDigit == "4") CurrentTen = 4 ElseIf (CurrentDigit == "5") CurrentTen = 5 ElseIf (CurrentDigit == "6") CurrentTen = 6 ElseIf (CurrentDigit == "7") CurrentTen = 7 ElseIf (CurrentDigit == "8") CurrentTen = 8 ElseIf (CurrentDigit == "9") CurrentTen = 9 ElseIf (CurrentDigit == "A") CurrentTen = 10 ElseIf (CurrentDigit == "B") CurrentTen = 10 ElseIf (CurrentDigit == "C") CurrentTen = 12 ElseIf (CurrentDigit == "D") CurrentTen = 13 ElseIf (CurrentDigit == "E") CurrentTen = 14 ElseIf (CurrentDigit == "F") CurrentTen = 15 Else CurrentTen= 0 EndIf CurrentTen = CurrentTen*(Math.POW(16, Length2-(LengthDone2+1)) as Int) SoFar2 += CurrentTen LengthDone2 += 1 EndWhile Return SoFar2EndFunction
Also, yes, I'm aware the ModIDs array won't work forever because there can be up to 256 mods. Nonetheless, it's set correctly (I checked), so that's not the problem (I only have 7 mods loading, and that includes the DLC).