Jump to content

Why does this piece of code stop halfway through? [Solved]


Recommended Posts

Posted

This function I've written keeps freezing after "Debug.Trace("COMPARING: " + mArmor.Getname() + " TO " + mArmor2.GetName())" and the script seems to stop responding. Additionally, after this has happened there's suddenly a large lag-spike when trying to access the inventory for about 2-3 seconds each time I try to access it.

 

rc_list_ArmorLists is a Formlist with 2 formlists within it, entry 2 being the list that it's looking for.

Entry 2 is a Formlist containing 5 armors, and the first entry on that formlist has the same name as mArmor.

 

 

Form Function mNextArmor(Armor mArmor)
	Formlist mArmorTypeList
	Armor mArmor2
	int i = rc_list_ArmorLists.GetSize() - 1
	string mName = mArmor.Getname()

		While i > -1
		
			mArmorTypeList = rc_list_ArmorLists.GetAt(i) as Formlist				;Fetches a Formlist of armors from the master list of Formlists.
			mArmor2 = mArmorTypeList.GetAt(0) as Armor						;Set a temporary Armor Form to point at the first entry in the targeted list of armors.
			
			Debug.Trace("playerArmor EQUALS: " + playerArmor)
			
			Debug.Trace("COMPARING: " + mArmor.Getname() + " TO " + mArmor2.GetName())
			Debug.Trace("rc_ArmorCount EQUALS: " + rc_ArmorCount)
			
			string mName2 = mArmor2.Getname()
			
			if mName == mName2									;If the first armor in the found Formlist has the same name as mArmor, it should be the right list.
				rc_ArmorCount += 1
				Debug.Trace("rc_ArmorCount EQUALS: " + rc_ArmorCount)
				mArmor = mArmorTypeList.GetAt(rc_ArmorCount) as Armor				;Points the armor to be equipped to be an identical but separate armor from the list.
				i = -1
				Debug.Trace("MATCH FOUND!")
			else
			Debug.Trace("MATCH NOT FOUND!")
			i -= 1
			endif
					
			
		endwhile

return mArmor
EndFunction

 

 

The point of this code is to take the name of the input armor and compare it to the name of the first entry in each formlist contained by rc_list_ArmorLists. If the name is the same, rc_ArmorCount increases by 1, mArmor is set to point to the armor in entry number "rc_ArmorCount" in that particular list and then mArmor is returned to the function which called this function. 

 

rc_ArmorCount is a Property which is defined like this:

 

 

int Property rc_ArmorCount
  Function Set(int newValue)
    if newValue > 5
      rc_ArmorCount = 0
    endIf
  EndFunction
  int Function Get()
    return rc_ArmorCount
  EndFunction
EndProperty

 

 

 

I can't for the life of me figure out why this keeps freezing. Any help would be appreciated, thanks in advance.

Posted

Many errors n your code:

 

 

Form Function mNextArmor(Armor mArmor)
  Formlist mArmorTypeList
  Armor mArmor2
  int i = rc_list_ArmorLists.GetSize() ; "ERROR: do not start with the item-1 or you may fail"
  string mName = mArmor.Getname()
 
  While i ; "ERROR: check just if it is zero, way faster"
    i-=1 ; "CHANGE: this is the trick to have always the correct numbers"
 
    mArmorTypeList = rc_list_ArmorLists.GetAt(i) as Formlist ;Fetches a Formlist of armors from the master list of Formlists.
    mArmor2 = mArmorTypeList.GetAt(0) as Armor ;Set a temporary Armor Form to point at the first entry in the targeted list of armors.
 
    Debug.Trace("playerArmor EQUALS: " + playerArmor)
    Debug.Trace("COMPARING: " + mArmor.Getname() + " TO " + mArmor2.GetName())
    Debug.Trace("rc_ArmorCount EQUALS: " + rc_ArmorCount)
 
    string mName2 = mArmor2.Getname()
 
    if mName == mName2 ;If the first armor in the found Formlist has the same name as mArmor, it should be the right list.
      rc_ArmorCount += 1
      Debug.Trace("rc_ArmorCount EQUALS: " + rc_ArmorCount)
      mArmor = mArmorTypeList.GetAt(rc_ArmorCount) as Armor ;Points the armor to be equipped to be an identical but separate armor from the list.
      i = 0 ; "CHANGE: this is the way to end"
      Debug.Trace("MATCH FOUND!")
    else
      Debug.Trace("MATCH NOT FOUND in position " + i + "!") ; "CHANGE: added the current index"
    endif
  endwhile
  return mArmor ; "WHY?: This is exaclty what you passed as input"
EndFunction
 
; "BIG PROBLEM ON YOU PROPERTY IMPLEMENTATION: You cannot have the name of the property and its value as the same variable"
 
int _rc_ArmorCount
int Property rc_ArmorCount
  Function Set(int newValue)
    if newValue > 5
      _rc_ArmorCount = 0
    else
      _rc_ArmorCount =newValue
    endIf
  EndFunction
  int Function Get()
    return _rc_ArmorCount
  EndFunction
EndProperty
 

 

 

I hope this will help.

 

Posted

This works. The issue seems to have either been from the Formlist initiation or the rc_ArmorCount property.

 

I would assume the latter. This is my first time using a customized property in Papyrus, that's where it went wrong.

 

In regards to return mArmor:

mArmor gets set to point to an entry in the matched Formlist, each time this is called the index it gets set to increases by 1.

Thanks to the set property of rc_ArmorCount, this count resets to 0 when it hits 6, starting the count over.

 

The returned mArmor is not the same value that was input, it's been overwritten by another armor in the matched formlist.

The original value of mArmor was used to find the correct formlist containing the desired new armor.

 

Thanks for the feedback. Problem solved, work continues.

 

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

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