public class CharacterData
{
public int m_ID;
public string m_Name;
//points
public float m_Exp;
public void SomeMethod()
{
m_Exp = 25;
}
// the rest removed for readability
}
This does not give errors, and shows log
static void ParseCharacters()
{
string filePath = Application.dataPath + "/DesignDataCSV/Characters.csv";
if (!File.Exists(filePath))
{
Debug.LogError("Missing Data: " + filePath);
return;
}
string[] readText = File.ReadAllLines("Assets/DesignDataCSV/Characters.csv");
for (int i = 0; i < readText.Length; ++i)
{
string[] values = readText[i].Split(',');
for (int j = 0; j < values.Length; ++j)
{
CharacterData characterData = new CharacterData();
characterData.SomeMethod();
Debug.Log(characterData.m_Exp);
}
}
}
}
I’m building this off of tutorials trying to learn some of the ins and outs of the language, so the .csv is very much bare bones in excel.
If the issue is how the code is written perhaps it gets addressed further in the tutorial.
If you have a string such as “123” and want to turn it into an integer or float using int.Parse(); or int.TryParse();, then that string must be absolutely sanitized spotlessly clean.
This means that the string cannot have ANY other non-numeric characters in it, such as spaces or even newlines. Even a blank string with nothing is typically considered invalid.
Unfortunately both spaces and newlines are invisible when printed out in the console.
To see such things, always put brackets around in your Debug.Log() statements, like so:
Debug.Log("[" + TheStringIWantToParse + "]);
Another way is to iterate all the characters with a for() loop and spit them out one at a time and see if there are any that don’t even show up in the log at all:
for (int i = 0; i < TheStringIWantToParse.Length; i++)
{
int c = TheStringIWantToParse[i];
Debug.Log("Character at position " + i + " is ASCII " + c);
}
Whatever your issue ends up being, you may need to manipulate the string to remove the illegal character(s). Look up any good C# tutorial on string manipulation for how to do this step, which will be completely dependent on what your actual illegal characters are.
string c = values[j];
Debug.Log("Character at position " + j + " is ASCII " + c);
Character at position 2 is ASCII 150
UnityEngine.Debug:Log (object)
CharacterInfoViewParser:ParseCharacters () (at Assets/Scripts/Editor/Parser/CharacterParser.cs:33)
150 is the exp float that fails. Does this mean anything?
I also opened the .csv as a .txt file, and all the fields were separated by commas. no white space/tabs.
Extract the string you’re working on (probably values[2] in your original code, line 11… what line did the original error happen on? That’s important!!) and check that string’s characters. Yes, it looks like 150 but there might be more in there.
I was thinking more about constructing the array without reading the file. Parsing a single float wouldn’t be an issue.
Clearly a bit of debugging is called for but what I would do in the interest of time is to try changing the value in that cell. I would edit it and test. I would copy one that worked and test. I’d swap the rows and test. I might skip over that cell and test.
If it can parse everything except for that cell it points to something amiss with that cell’s value. If it can’t parse 150 no matter where you place it that indicates that there is something amiss with the number 150 (which there won’t be).
I tried a few variations. I’ve tried swapping the values in the .csv, I’ve tried swapping values in the loops.
I tried disabling values of strings/hash that come before it.
The result is the same. Once it hits a float, any float, it gives an error.
On top of all that,
I tried copying to google sheets. I tried downloading both csv, and tsv. tried using \t to split.