Text to Variables

Hi, I want to make a script that reads a text file and puts each line into a variable, something like this:

Text file:

number1

number2

Script:

var number1 = textline 1

var number2 = textline 2

Something like that, but i dont know how, please help me.

Could use

[1], it's great for those stuff.


  [1]: http://www.unifycommunity.com/wiki/index.php?title=TinyXmlReader

I’m not sure if this is the best way to do it, but we shall see. You could use StreamReader, one of the System.IO classes. Eric5h5 does a demonstration on how to utilise lines from a .txt file in this post.

From his code, all you would need to do is add your variables var number1 : String; and var number2 : String; to the beginning of the script and then, at the end of the Start() function replace

for (line in lines) {
        print (line);

with:

number1 = lines[1];
number2 = lines[2];
//any further variables you have

That’s basically it. If you have a large amount of lines you want to pass through variables, you would probably need a for loop of some kind to make life simpler. However, I’m not so great with for loops to be honest (barely ever used them), so I probably wouldn’t be able to help you on that one. :wink:

Hope that helps, Klep