This is a common problem, so though I might post it here if anyone wonders ever again:
Ronitmaddy asked this at the GMC today:
“I know how to make GM read the first line of text file and show it using ‘show_message’ command but I want to make the GM read second ,third ar any number of line that I want and show the content of the file using ‘show_message’ command. Anyone knows how to do it?”
I immediately clicked the reply button, but when I had posted mine I saw that there was already a reply before me. It was Master Pobble-Wobble and he gave the following solution:
file[0] = file_text_open_read(fname);
i = 0;
do
{
str[i] = file_text_read_string(file[0]);
file_text_readln(file[0]);
i += 1;
show_message(str[i]);
}
until ( file_text_eof(file[0]) == true )
It is a very good solution. I recommend you to use it. Once you have read the file like this you write out, for an example, line 15 by calling for str[15]. However, I was in a rush and my solution was thus more specific:
string = "";
nr = 5; //You want to read line five
i = 1;
while (!file_text_eof(file)) {
if (i==nr) {
string = file_text_read(file);
}
file_text_readln(file);
}
This will return only the value of the certain, indicated, line. Works nice as well, use any method but do not ever again ask… or well, ask, if you don’t understand. And never hesitate to comment articles by the way.
.
Users logged in:
Comments
Loading comments...