passing an arraylist to a separate script

Say I wanted to pass an array of attributes to my “save attributes” method.
I put the array together on the character generator script, then call the function:
GameSettings.SaveAttributes(myAttributes); //I’m missing something here…

I had defined the arraylist at the top along with the other variables, and added several items such as: myAttributes.Add("Constitution: "+ _constitution); myAttributes.Add("Strength: "+ _strength); myAttributes.Add("Stamina: "+ _stamina);
Can I do it this way? Looking to save the label and the stat value generated.

In my saving script, the struct is:
public static void SaveAttributes(myAttributes attribute){
for(int ctr=0; ctr < myAttributes.Length; ctr++){
PlayerPrefs.SetInt(myAttributes[ctr]);
}
}
Only it’s not getting the reference from the generation script.

Thanks!

As I see it, you’re passing a variable called attribute of type myAttributes. Then, in your code, you’re requesting an item from a list called myAttributes - but nowhere do I see such a list being created. I believe your code should instead read:

public static void SaveAttributes(myAttributes[] attribute)
{ 
  for(int ctr=0; ctr < attribute.Length; ctr++)
  { 
    PlayerPrefs.SetInt(attribute[ctr]); 
  } 
}

Also, from the context it appears that myAttributes is being populated with strings. Then you pass this to GameSettings and there you use SetInt - shouldn’t this be SetString?