File read/write

You must understand the Game Editor concepts, before post here.

File read/write

Postby Joshua Worth » Tue Feb 21, 2006 5:57 am

how do you you use the file read/write functions?
Stay sweet
User avatar
Joshua Worth
 
Posts: 515
Joined: Tue Jul 19, 2005 12:00 am
Location: Stralia
Score: 5 Give a positive score

Postby makslane » Tue Feb 21, 2006 6:25 pm

Do you mean saveVars?
Game Editor is an open source game creator software that's wants to pay it's developers to keep evolving.
If you like Game Editor, make a review!
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby Joshua Worth » Tue Feb 21, 2006 9:05 pm

No, I mean fopen+fclose etc.
Stay sweet
User avatar
Joshua Worth
 
Posts: 515
Joined: Tue Jul 19, 2005 12:00 am
Location: Stralia
Score: 5 Give a positive score

Postby makslane » Wed Feb 22, 2006 2:31 pm

You can see example in standard C programs.
Look at google for fopen, fwrite, ...
Game Editor is an open source game creator software that's wants to pay it's developers to keep evolving.
If you like Game Editor, make a review!
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby Joshua Worth » Sat Feb 25, 2006 10:57 am

can you give me a straight foward way to open a text file, read each line, turn them into integers instead of strings, and put each into an array.
Stay sweet
User avatar
Joshua Worth
 
Posts: 515
Joined: Tue Jul 19, 2005 12:00 am
Location: Stralia
Score: 5 Give a positive score

Postby makslane » Sat Feb 25, 2006 11:07 am

What's the file format?
Something like this?

10
12
30
45
Game Editor is an open source game creator software that's wants to pay it's developers to keep evolving.
If you like Game Editor, make a review!
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby Joshua Worth » Sat Feb 25, 2006 10:09 pm

yes
Stay sweet
User avatar
Joshua Worth
 
Posts: 515
Joined: Tue Jul 19, 2005 12:00 am
Location: Stralia
Score: 5 Give a positive score

Postby Joshua Worth » Mon Feb 27, 2006 9:03 pm

Please give me an answer quickly, i havent got long :shock: :!:
Stay sweet
User avatar
Joshua Worth
 
Posts: 515
Joined: Tue Jul 19, 2005 12:00 am
Location: Stralia
Score: 5 Give a positive score

Postby makslane » Tue Feb 28, 2006 7:55 pm

Put this code in the Global Code editor:

Code: Select all
int readLines(char *fileName, int max, long *array)
{
   int i = 0;
    FILE *fp = fopen(fileName, "r");
    if(fp)
    {
        while(fscanf(fp, "%d", &array[i]) > 0)
      {
        i++;
      }
       
      fclose(fp);
    }

  //Number of read lines
   return i;
}



If you are using a array of integer (with 100 elements), you can use this code in the Script Editor:

Code: Select all
readLines("file.txt", 100, myArray);


Download the sample here:
http://game-editor.com/examples/readlines.zip
Game Editor is an open source game creator software that's wants to pay it's developers to keep evolving.
If you like Game Editor, make a review!
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby Joshua Worth » Wed Mar 01, 2006 6:44 am

thankyou soooooooooooooooooooooooooooooo much!!!!!!!!! :D :D :D :D :D :D
Stay sweet
User avatar
Joshua Worth
 
Posts: 515
Joined: Tue Jul 19, 2005 12:00 am
Location: Stralia
Score: 5 Give a positive score

Postby Joshua Worth » Wed Mar 08, 2006 6:24 am

How can i make it read into a string instead?
Stay sweet
User avatar
Joshua Worth
 
Posts: 515
Joined: Tue Jul 19, 2005 12:00 am
Location: Stralia
Score: 5 Give a positive score

Postby makslane » Wed Mar 08, 2006 12:31 pm

Create a array of strings and use the code:

fscanf(fp, "%s", array[i]) //Without &
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby Joshua Worth » Wed Mar 08, 2006 8:55 pm

I have to change the long *array at the top dont i?
Stay sweet
User avatar
Joshua Worth
 
Posts: 515
Joined: Tue Jul 19, 2005 12:00 am
Location: Stralia
Score: 5 Give a positive score

Postby makslane » Thu Mar 09, 2006 2:13 am

yes
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby Joshua Worth » Fri Mar 10, 2006 5:27 am

what to?
Stay sweet
User avatar
Joshua Worth
 
Posts: 515
Joined: Tue Jul 19, 2005 12:00 am
Location: Stralia
Score: 5 Give a positive score

Next

Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest