I’ve made code to read line by line text and create a construct with informaton contained in each line. When ruuning game at unity i got error
however as I examined code i couldn’t find any mistakes, I’m still a newbie at c# so i may missed something, help please.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
public class dialogue : MonoBehaviour
{
public TextAsset spellData;
struct DialoguLine
{
public string name;
public string content;
public string[] options;
public DialoguLine(string Name, string Content)
{
name = Name;
content = Content;
options = new string[0];
}
}
List<DialoguLine> lines;
private void Start()
{
lines = new List<DialoguLine>();
loadd(spellData);
}
void Update () {
}
void loadd(TextAsset spellData)
{
string fs = spellData.text;
string[] flines = Regex.Split(fs, "\n|\r|\r\n");
for ( int i=0; i < flines.Length; i++)
{
string linecontent = flines[i];
string[] tline = Regex.Split(linecontent, ";");
if (tline[0] == "player")
{
DialoguLine nextl;
nextl.name = tline[0];
nextl.content = "";
nextl.options = new string[tline.Length - 1];
for (int j = 1; j < tline.Length; j++)
{
nextl.options[j - 1] = tline[j];
}
lines.Add(nextl);
}
else
{
DialoguLine nextl;
nextl.name = tline[0];
nextl.content = tline[1]; // << at this line unity get error
nextl.options = new string[0];
lines.Add(nextl);
}
}
}