How to move my character by getting input from text file?

i want to move my character in the game from input through a text file. On 1 i want to move it right…On 0-Idle and on -1 towards left…i am using the following code:

var fileContents = sr.ReadToEnd();
sr.Close();

var lines = fileContents.Split("

"[0]);
for (line in lines) {

    h = TryParseInt(line);

This code moves the character to left when i ONLY give -1 in the txt file and to right when i give only 1 and remains idle when i give ONLY 0…bt when i give inpput “1,0,-1” together it does not give the desired result of moving first “right,idle,left”.

Please help me with this as i am new to programming so i dnt know alot and hence asking this question.

Thankyou.

I’ve not tried the code myself but it seems to me that if you’re storing your moves as 1,0,1,1,0 that when you try and parse that line, you’re trying to parse the whole thing instead of the numbers from it. Try:

var moves = line.Split(“,”);

then iterate through each of the moves in the ‘moves’ variable. i.e.

for (line in lines) {

var moves = line.Split(",");

foreach (string move in moves) {

h = TryParseInt(move);