using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class FunctionTransformers : MonoBehaviour {
public List<string> list1;
public List<string> list2;
// Use this for initialization
void Start ()
{
splitStringToList (list1, "Optimus:90,Bumblebee:45,Jazz:12", ",");
foreach(string s in list1)
{
splitStringToList (list2, s , ":");
int tInt = int.Parse (list2[1]);
if (tInt >= 100 & tInt > 66)
{
Debug.Log (list2[0] + " health is GOOD - (" + tInt + "HP)");
}
else if (tInt >= 65 & tInt > 33)
{
Debug.Log (list2[0] + " health is FAIR - (" + tInt + "HP)");
}
else
{
Debug.Log (list2[0] + " health is POOR - (" + tInt + "HP). Seek medical attention.");
}
};
}
List<string> splitStringToList (List<string> tList, string myString, string mySplit)
{
tList = new List<string>(myString.Split(mySplit [0]));
return tList;
}
}
So after troubleshooting this I found that if you debug.log tList[0] inside the function splitStringToList it gets the information, but it doesn’t store it in the lists I direct it to even though I tell it to return the values. How can I get the function splitStringToList to return the values to my lists?
The error message is for line 14 (foreach(string s in list1)) and it says argument is out of range. It is referring to list1 because the values weren’t stored after calling on the splitStringToList function the first time.