Jump to content

Copying an array to another.


Recommended Posts

I don't know how to do that. I'm not that far into arrays. Not that good with them.. but they are faster than typing a billion if/elseif statements..

 

Nevermind, I'll just think of a traditional longer way to do it. Whenever I look to arrays to make things easier, I get stuck because I can't get help with certain parts of it. It's not that well explained on the wiki, or well anywhere.

Edited by TummaSuklaa
Link to comment
Share on other sites

Heres my untested guess. I did not use any recursive pattern. I used a loop pattern involving the current index and length of the array. For each element in "fromArray" I add it to the "toArray". I am not checking for duplicates or none elements.

Function CopyTo(var[] fromArray, var[] toArray) Global
	If (fromArray && toArray) ; does not equal none
		int idx = -1

		While(idx < fromArray.Length)
			idx += 1
			toArray.Add(fromArray[idx])
		EndWhile
	EndIf
EndFunction
Link to comment
Share on other sites

 

Heres my untested guess. I did not use any recursive pattern. I used a loop pattern involving the current index and length of the array. For each element in "fromArray" I add it to the "toArray". I am not checking for duplicates or none elements.

Function CopyTo(var[] fromArray, var[] toArray) Global
	If (fromArray && toArray) ; does not equal none
		int idx = -1

		While(idx < fromArray.Length)
			idx += 1
			toArray.Add(fromArray[idx])
		EndWhile
	EndIf
EndFunction

You forgot a return statement. That function won't do anything worthwhile since Papyrus function parameters are passed by value, not reference. Other than that, it looks good.

Edited by Reneer
Link to comment
Share on other sites

  • Recently Browsing   0 members

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