Page 2 of 2

PostPosted: Fri Mar 10, 2006 12:15 pm
by makslane
1) In the Variables panel, change the type of myArray variable to String
2) Change the readLine function to:

Code: Select all
int readLines(char *fileName, int max)
{
   int i = 0;
    FILE *fp = fopen(fileName, "r");
    if(fp)
    {
        while(fgets(myArray[i], 256, fp)) //fgets used to get the whole line
      {
        i++;
      }
 
      fclose(fp);
    }

  //Number of read lines
   return i;
}


3) Change the action code to:

Code: Select all
int total;

total = readLines("file.txt", 100);
strcpy(debug1.text, myArray[0]);
debug2.textNumber = total;

PostPosted: Sun Apr 23, 2006 12:00 pm
by DilloDude
How could this be modified to return just one string? I'm thinking for some things it would be easier to write a peice of text in notepad, rather than in the script editor. For exmple, loading the txt file with:
There was this stuff happenning.
Someone shot someone else.
Another guy exploded.
And using
Code: Select all
readfile(writing);
strcpy(text, writing);

Would be easier than saying
Code: Select all
strcpy(text, "There was this stuff happening.\nSomeone shot someone else.\nAnother guy exploded.");

Also, it would be better where you want a lot of text, like in credits, or reading a story.