This function was born out of this problem:
I have an array of strings, let's call it Array A. I have another array of strings, let's call it Array B. How do I check which Strings from A are also in B, and how do I collect and use that data? This function will create Array C and return it, with Strings (re-purpose as you need for Forms, or Weapons etc) that appear in Array A and Array B, taking B as the main list, A as the reference.
It uses a lot of all-purpose array functions created by Chesko in this post - http://www.gamesas.com/topic/1365378-exampleresourcegeneral-purpose-array-functions/
The following are required (written in the default Form state, I changed mine to String)
int function ArrayCount(Form[] myArray)int function ArrayHasForm(Form[] myArray, Form myForm)bool function ArraySort(Form[] myArray, int i = 0)bool function ArrayAddForm(Form[] myArray, Form myForm)
Here is the function! Hopefully it is of some use:
String Function GetCombinedArrayTwo(String[] StringArrayA = none, String[] StringArrayB = none) ;By B1gBadDaddy ;This function will compare two arrays, and return a new array of objects that were ;present in both of them. It compares from Array A to Array B, and requires a few ;all-purpose array functions created by Chesko. #Legend ;Example: ;Array A is a list of some weapons. Array B is another list weapons. ;You want to create Array C, which contains weapons that appear in both A and B. String[] CombinedArray = new String[15]; let's create our new Combined Array, set your desired slots int iALength = StringArrayA.Length; Array A is the Array of objects you're looking for. We walk through this array. int iBLength = StringArrayB.Length; Array B is the Array of objects you're checking against While iALength; while there are objects unchecked in Array A iALength -= 1 String myString = StringArrayA[iALength] if ArrayHasForm(StringArrayB, myString); is myString present in Array b? ArrayAddForm(CombinedArray, myString) endif EndWhile ArraySort(CombinedArray) Return CombinedArrayEndFunction
A few issues:
Your array, depending on how big you set it, may have none entries. Use Chesko's Count function to see how many are not none.
Example results:
I thought it best to write a quick example.
"One"
"Two"
"Three"
Array B:
"One"
"Two"
"Three"
"Four"
"Five"
Array C will be:
"One"
"Two"
"Three"