Jump to content

Need help filling away from secondary script


Xander9009

Recommended Posts

Gosh dang it. I meant array...

 

I've got two scripts. The first has an array property. The second is supposed to fill the array. I can't just combine them because in the end there will be a lot more doing the same thing. Here are the two scripts.

Scriptname APU_ManagerScript extends Quest  

Int[] Property CurrentIDs Auto
Int[] Property CurrentLevels Auto
String[] Property CurrentFiles Auto

Bool[] Property Test Auto

Int[] Property AlchemyIDs Auto
Int[] Property AlchemyLevels Auto
String[] Property AlchemyFiles Auto

Float NewLevel
Bool Filled

Event OnInit()
	Test[0] = True
EndEvent

Event OnStoryIncreaseSkill(string asSkill)
	NewLevel = Game.GetPlayer().GetAV(asSkill)
	Filled = False
	If ( asSkill == "Alchemy" )
		CurrentIDs = AlchemyIDs
		CurrentLevels = AlchemyLevels
		CurrentFiles = AlchemyFiles
		Filled = True
	EndIf
	If ( Filled  )
		Int i = 0
		While ( i < CurrentIDs.Length )
			If ( NewLevel >= CurrentLevels[i] )
				If !( Game.GetPlayer().HasPerk(Game.GetFormFromFile(CurrentIDs[i], CurrentFiles[i]) as Perk) )
					Game.GetPlayer().AddPerk(Game.GetFormFromFile(CurrentIDs[i], CurrentFiles[i]) as Perk)
				EndIf
			EndIf
			i += 1
		EndWhile
	EndIf
	Stop()
EndEvent
Scriptname APU_PerkSetup_Main extends Quest  

APU_ManagerScript Property APU_ManagerQuest Auto
Bool Done = False

Event OnInit()
	(APU_ManagerQuest as APU_ManagerScript).Test[0] = true
EndEvent

The first one works fine. The second one gives me the error "required (...)+ loop did not match anything at input '=' " at the line in the OnInit(). If I make it reference something that's not an array, it works perfectly fine. But as an array, it just won't compile. I've done this before in another mod, but it doesn't seem to want to cooperate this time. Anyone have any ideas? I'm hoping it's something simple.

 

So, after some testing, I've found that I can get the value, I just can't set the value. I can, however, do this

(APU_ManagerQuest as APU_ManagerScript).AlchemyIDs = New Int[128]
Edited by Xander9009
Link to comment
Share on other sites

Since the previous method wasn't working (and I can't tell why), I tried another method. This time, I'm using a function to send the relevant arrays to the main script, and then doing the calculation there. But that's giving me all kinds of weird problems.

 

Main script

 

 

Scriptname APU_ManagerScript extends Quest  

Int[] Property CurrentIDs Auto
Int[] Property CurrentLevels Auto
String[] Property CurrentFiles Auto

Int[] Property AlchemyIDs Auto
Int[] Property AlchemyLevels Auto
String[] Property AlchemyFiles Auto

Float NewLevel
Bool Filled

Function UpdateSkill(String asSkill)
Debug.Notification("4")
	NewLevel = Game.GetPlayer().GetAV(asSkill)
	Filled = False
	If ( asSkill == "Alchemy" )
		CurrentIDs = AlchemyIDs
		CurrentLevels = AlchemyLevels
		CurrentFiles = AlchemyFiles
		Filled = True
	EndIf
	If ( Filled  )
		Int i = 0
		While ( i < CurrentIDs.Length )
			If ( NewLevel >= CurrentLevels[i] )
				If !( Game.GetPlayer().HasPerk(Game.GetFormFromFile(CurrentIDs[i], CurrentFiles[i]) as Perk) )
					Game.GetPlayer().AddPerk(Game.GetFormFromFile(CurrentIDs[i], CurrentFiles[i]) as Perk)
					Debug.Notification((Game.GetFormFromFile(CurrentIDs[i], CurrentFiles[i]) as Perk).GetName()+" unlocked")
				EndIf
			EndIf
			i += 1
		EndWhile
	EndIf
EndFunction

Function AppendArray(String SkillRef, Int[] IDs, Int[] Levels, String[] Files)
	If SkillRef == "Alchemy"
		CurrentIDs = AlchemyIDs
		CurrentLevels = AlchemyLevels
		CurrentFiles = AlchemyFiles
	EndIf

	Int j = CurrentIDs.Length
	Int i = 0
	Debug.Notification("1.1 IDs.Length = "+IDs.Length)
	While ( i < IDs.Length )
;		If ( Array2.Find(Array1[j]) < 0 )
			CurrentIDs[j] = IDs[i]
			CurrentLevels[j] = Levels[i]
			CurrentFiles[j] = Files[i]
;		Else
;			Int k = Array2.Find(Array1[j])
;			Array4[k] = Array3[i]
;			Array6[k] = Array5[i]
;		EndIf
		Debug.Notification("1.2 IDs["+i+"] : "+IDs[i])
		Debug.Notification("Levels["+i+"] : "+Levels[i])
		Debug.Notification("Files["+i+"] : "+Files[i])
		Debug.Notification("1.3 CurrentIDs["+j+"] : "+CurrentIDs[j])
		Debug.Notification("CurrentLevels["+j+"] : "+CurrentLevels[j])
		Debug.Notification("CurrentFiles["+j+"] : "+CurrentFiles[j])
		j += 1
		i += 1
	EndWhile
	Debug.Notification("1.5")
EndFunction

 

 

 

Second script, this one fills it's own arrays, and then sends them to the main script where they're incorporated into its own arrays:

 

 

Scriptname APU_PerkSetup_Main extends Quest

APU_ManagerScript Property APU_ManagerQuest Auto
Bool Done = False
Int[] Property AlchemyIDs Auto
Int[] Property AlchemyLevels Auto
String[] Property AlchemyFiles Auto

Event OnInit()
	If !Done
		Utility.Wait(5)
		Debug.Notification("0")
		AlchemyIDs = New Int[2]
		AlchemyLevels = New Int[2]
		AlchemyFiles = New String[2]
		AlchemyIDs[0] = 778535
		AlchemyLevels[0] = 0
		AlchemyFiles[0] = "Skyrim.esm"
		AlchemyIDs[1] = 788426
		AlchemyLevels[1] = 25
		AlchemyFiles[1] = "Skyrim.esm"
		(APU_ManagerQuest as APU_ManagerScript).AppendArray("Alchemy", AlchemyIDs, AlchemyLevels, AlchemyFiles)
		Done = True
	EndIf
EndEvent

 

 

 

The issue is that the debug in the main script in the function AppendArray shows me that everything is working fine except CurrentFiles is returning the string "CurrentFiles[i". By that I mean CurrentFiles[0] is the string "CurrentFiles[0". Furthermore, if I comment out the 1.2 notifications, then suddenly, 1.3 CurrentIDs start returning CurrentLevels and a debug after the entire process tells me CurrentFiles[0] and [1] are empty entirely, now. I can't figure out what I'm doing wrong. These seem like impossible problems. Without changing any content, only changing notifications, the actual values are changing and returning values from the wrong array.

 

I should note I'm doing this on a new game every time. It's not left over data from a bad save, there aren't any saves.

Link to comment
Share on other sites

This looks strange but I take it for granted as I don't have CK near. Try:

Scriptname APU_PerkSetup_Main extends Quest  

APU_ManagerScript Property APU_ManagerQuest Auto
Bool Done = False

Event OnInit()
	(APU_ManagerQuest as APU_ManagerScript).setValueInArray(0,true)
EndEvent



;in the other script
....
function setValueInArray(int index, bool value)
   test[index]=value
endFunction
....
Edited by LukeH
Link to comment
Share on other sites

Thank you. That compiled without a problem, and thankfully, it's not giving me the same problems my second attempt did. I managed to get the scripts fully functional up to getting the arrays set up. It certainly made things more complicated, what with the fact that now my two scripts have a combined 438 lines, But at least it's working. And to be fair, the majority of that is simply because I need five total array for every skill.

Link to comment
Share on other sites

Alright, so I've got another issue that I can't seem to figure out. I've been working on it for a few hours and frankly I'm out of ideas. Don't judge too harshly, it was much cleaner before I started reworking things to fix this issue. Once I started that, it ended up a bit of a mess. I've marker the two lines of interest with ---'s

 

 

 

Scriptname APU_ManagerScript extends Quest  

Int[] Property CurrentIDs Auto
Int[] Property CurrentLevels Auto
String[] Property CurrentFiles Auto

Bool Property Busy Auto

Float NewLevel

Event OnInit()
	Busy = True
	Utility.Wait(3)
	Debug.Notification("APU Manager Script is initializing")
	AlchemyIDs = New Int[128]
	AlchemyLevels = New Int[128]
	AlchemyFiles = New String[128]
...
	CurrentIDs = New Int[128]
	CurrentLevels = New Int[128]
	CurrentFiles = New String[128]
	Debug.Notification("APU Manager Script has initialized")
	Busy = False
EndEvent

String Property ArrayRef Auto
Int Property Index Auto
Int Property IDValue Auto
Int Property LevelValue Auto
String Property StringValue Auto
Int Property Phase Auto
String Property asSkill Auto

Event OnUpdate()
	If ( Phase == 1 )
		Busy = True
;Debug.Notification("~3")
		If ( ArrayRef == "AlchemyIDs" )
			AlchemyIDs[Index] = IDValue
Debug.Notification("~3.1 -> ID: "+AlchemyIDs[Index]) ;--------------------------
		ElseIf ( ArrayRef == "AlchemyLevels" )
			AlchemyLevels[Index] = LevelValue
;Debug.Notification("~3.2 -> ID: "+AlchemyLevels[Index])
		ElseIf ( ArrayRef == "AlchemyFiles" )
			AlchemyFiles[Index] = StringValue
;Debug.Notification("~3.3 -> ID: "+AlchemyFiles[Index])
Debug.Notification("~3.1 -> ID: "+AlchemyIDs[Index]) ;----------------------------
...
EndEvent

Int[] Property AlchemyIDs Auto
Int[] Property AlchemyLevels Auto
String[] Property AlchemyFiles Auto
...

 

 

 

The problem is this: as the thing runs, it set's the values of AlchemyIDs to the ID, then it sets the AlchemyIDs to the levels. I can't figure out how it's doing that. It's back to the same problem I had in my second try previous. It should show this for my notifications

 

  1. 758...1
  2. 758...2
  3. 758...3
  4. 758...4
  5. 758...5

Instead I'm getting this

  1. 758...1
  2. 0
  3. 758...2
  4. 20
  5. 758...3
  6. 40
  7. 758...4
  8. 60
  9. 758...5
  10. 80

So, my values are being rewritten when they run again and I can't figure out why. Is it some glitch about how the program handles array names? Is it because the names are too similar? I changed the name of AlchemyLevels to A7Levels and now I get

 

  1. 758...1
  2. 0
  3. 758...2
  4. 758...3
  5. 758...4
  6. 758...5

But when I try calling the values back at a different time, they're all 0.

 

I started with functions instead of the OnUpdate event. I've tried shrinking the array initialization sizes. I originally wasn't initializing them at all. I've tried changing their names. I've tried everything I can think of that i figure might affect it. Nothing I do seems to make the values stick at all, let alone in the right array. For the record, the two arrays DO NOT interact as far as I can tell. The arrays and their values are completely isolated from one another, but they're crossing over and then emptying themselves. I can't figure out what's going on.

 

For the record, here's ALL the code that runs between when the first notification (758...1) and the second (0):

 

 

 

While ( ScriptRef.Busy == True )

EndWhile

 

ScriptRef.ArrayRef = LevelString

ScriptRef.Busy = True

ScriptRef.Phase = 1

ScriptRef.RegisterForSingleUpdate(0.01)

 

 

 

So it returns the right number, then runs the code above which only makes it wait until it's ready, sets the string name of the next array, sets it back to busy, makes sure it's still set to the first half of the onupdate, and sets it to update. NOTHING about AlchemyIDs is used again or referred to in any way, yet its value is changing. It changes ArrayRef before updating again. So, it should run through the update code with ArrayRef = LevelString, and that doesn't allow it access to AlchemyIDs at all.

 

Any solution to this would be immensely appreciated. I'm out of ideas. If these arrays won't work, I'll have to find another way to go about everything. And while I CAN find other ways that won't use, I really don't want to because arrays are the single best way to handle this many different but similar variables related to each other like this.

Link to comment
Share on other sites

Alright, so I never did figure out why it was doing that, but I converted to a system where the arrays are only ever changed based on what happens in that script. Any time I try changing them in a function that another script calls or from another script directly, it doesn't work. It's still behaving oddly, but it's working.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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