c# - Spliting into lines then into variables -
i have text file below:
001 bulbasaur 45 49 49 65 65 45 grass poison
002 ivysaur 60 62 63 80 80 60 grass poison
003 venusaur 80 82 83 100 100 80 grass poison
004 charmander 39 52 43 60 50 65 fire
005 charmeleon 58 64 58 80 65 80 fire
i have written piece of code split lines variables refuses work, apology's if asking in wrong place. (unity c# question).
var lines = textfile.text.split("\n"[0]); allmonsters = new monsters[lines.length]; list<string> linesplit = new list<string>(); (int = 0; < lines.length; i++) { debug.log(lines[i]); linesplit.clear(); linesplit = lines[i].split(' ').tolist (); int id = int.parse(linesplit[0]); string name = linesplit[1].tostring(); float hp = float.parse(linesplit[2]); float atk = float.parse(linesplit[3]); float def = float.parse(linesplit[4]); float spatk = float.parse(linesplit[5]); float spdef = float.parse(linesplit[6]); float speed = float.parse(linesplit[7]); firsttype ft = (firsttype)system.enum.parse(typeof(firsttype),linesplit[8]); secondtype st = (secondtype)system.enum.parse(typeof(secondtype),linesplit[9]); } the code works first line on second run of code null reference object error, please me.
note, variables assigned aren't overwritten after code.
edit: linesplit variable on 1200 elements long, not think unity clearing array issue?
i'm not sure second iteration, on 4th iteration line 004 charmander 39 52 43 60 50 65 fire have 9 parameters (by split of space) , using linesplit[9], there nullpointerexception.
Comments
Post a Comment