ID:167871
 
how do I read a plan text file line by line?
and load whats in that line (minus the return) into a var?
You can load an entire text file into a variable using file2text(). After that, you'll have to parse it yourself.
Why would you want to do that? Give a host some necessary abilites via text file rather than some verbs, such as a player maximum?
In response to Jon88 (#1)
CaptFalcon33035 im going to be loading level data vir a text file.

each line is 81 charslong.

if I use file2text does it put it all into 1 line?
if it does then I know how to read the file2text by line.
In response to Zmadpeter (#3)
Why don't you test it?

I take it that you are actually writing these text files, then? Otherwise, it's useless, not to mention easily corrupted.
In response to CaptFalcon33035 (#4)
the idea is I can add more levels to the game and then each time the game starts it checks the hub (this is a hidden hub)
that has the current version number if they dont match it downloads the update and blamo more levels without having to update the game its self.

why dont I test it... well im working on adding levels right now it takes a while to check there ok (about 1 to 5 mins a level) then adding the level code to the file (this version im working on has the first 100 levels) can you please test it :P
In response to CaptFalcon33035 (#2)
There's a variety of reasons.

Zmadpeter, you can't read a text file line by line. You can, however, get the entire thing, then parse it yourself.

(I assume this is for your sudoku game?)

Given that you've said each line is exactly 81 characters long, you can just do this:

var/list/strings=list()
var/t=file2text('randomfile.txt')
while(t)
strings+=copytext(t,1,81)
t=copytext(t,82,0)
In response to Jp (#6)
thank you I will give that I try after im done with the first 50 levels.
In response to Zmadpeter (#5)
You're going to have to do it Jp's way because it gives you a single line. Maybe rtf would show it differently, but aside from that, you need to make sure that every line has no more than 81 or 82 characters, unless of coase, you want to number them. Then you can just take a for() loop, count up the lines, and create a level based on that.
In response to Zmadpeter (#7)
Of course, if the lines could be any length, then you'd have to search for a newline character. The code would actually be very similar:

var/list/strings=list()
var/t=file2text('randomfile.txt')
var/k
while(t)
k=findtext(t,"\n")
strings+=copytext(t,1,k)
t=copytext(t,k+1,0)