Strange issues with arrays

Post » Thu Jan 23, 2014 10:15 pm

I have two functions. The first is supposed to get an array of actors and then calculate and save a percentage of the actor's health/magicka/stamina into three different arrays:

Spoiler
float[] test2actor[] _actorListint lengthOfActorListfloat[] _RestoreHealthfloat[] _RestoreMagickafloat[] _RestoreStaminaevent OnInit()		RegisterForSingleUpdate(60.0)	endEventevent OnPlayerLoadGame()			endEventfunction calculateMainAttributes_N(actor[] actorList)		test2 = new float[3]		_RestoreHealth = None	_RestoreMagicka = None	_RestoreStamina = None		_actorList = actorList		float RestoreHealthTotal	float RestoreMagickaTotal	float RestoreStaminaTotal		float RestoreHealth	float RestoreMagicka	float RestoreStamina		float temp				lengthOfActorList = actorList.length		_RestoreHealth = new float[1]	_RestoreMagicka = new float[1]	_RestoreStamina = new float[1]		int i = 0	while i < lengthOfActorList				temp = 0.05 ;delete this after testing		RestoreHealthTotal = ((actorList[i].GetActorValue("Health") / actorList[i].GetActorValuePercentage("Health"))) * temp                RestoreHealth = RestoreHealthTotal		_RestoreHealth[i] = RestoreHealthTotal				;test2[0] = RestoreHealth				temp = 0.20 ;delete this after testing		RestoreMagickaTotal = ((actorList[i].GetActorValue("Magicka") / actorList[i].GetActorValuePercentage("Magicka"))) * temp                RestoreMagicka = RestoreMagickaTotal		_RestoreMagicka[i] = RestoreMagickaTotal				;test2[1] = RestoreMagicka				temp = 0.50 ;delete this after testing		RestoreStaminaTotal = ((actorList[i].GetActorValue("Stamina") / actorList[i].GetActorValuePercentage("Stamina"))) * temp                RestoreStamina = RestoreStaminaTotal		_RestoreStamina[i] = RestoreStaminaTotal				;test2[2] = RestoreStamina				i += 1	endWhile		RegisterForSingleUpdate(60.0)			endFunction

The next function is supposed to read those arrays (for now) prints them to the screen:

Spoiler
function update_N()		debug.Notification("test2[0] = " + test2[0])	debug.Notification("_RestoreHealth[0] = " + _RestoreHealth[0])	debug.Notification("_RestoreMagicka[0] = " + _RestoreMagicka[0])	debug.Notification("_RestoreStamina[0] = " + _RestoreStamina[0])	endFunction

Now, this is what happens:

If I let the script run "test2[0]", "RestoreHealth[0]", "RestoreMagicka[0]", "RestoreStamina[0]" are all 0, or maybe not even initialized. If I uncomment the line "test2[0] = RestoreHealth" all variables are 5 (assuming the character had 100 health), if I uncomment "test2[1] = RestoreMagicka" all values are 20, and when I uncomment "test2[2] = RestoreStamina" all values are 50.

Note: While trying to solve this issue I've simplified the calculations more and more; it seems that now uncomment the "test[2] = ..." has no effect, I still get the value 0 for all variables.

If I use "float _RestoreHealthTotal" instead of "float[] _RestoreHealthTotal" and remove the while loop the script works as intended so the error has to be somewhere in the while loop.

User avatar
Eve(G)
 
Posts: 3546
Joined: Tue Oct 23, 2007 11:45 am

Return to V - Skyrim