Jump to content


Photo

Error opening file for reading.


  • Please log in to reply
5 replies to this topic

#1 Tzunami

Tzunami

    GMC Member

  • GMC Member
  • 321 posts
  • Version:GM:Studio

Posted 01 April 2012 - 02:07 AM

Hi GMC,

I have tried many many different ways to get this to work but none have provailed. I simply want to open a file so that I can write, and read from it. So far the writing works perfectly, but no matter what I try, the reading has ALWAYS failed. Below is the code I have finally ended up at, which does not work. What am I doing wrong?

user = get_string("Enter username:","");
map = file_text_open_write(user +".txt");
contents = file_text_open_read(user +".txt");
show_message(file_text_readln(contents));

EDIT: error message reads "Error opening file for reading."

Regards,
Tzunami

Edited by Tzunami, 01 April 2012 - 04:10 AM.

  • 0

#2 Tzunami

Tzunami

    GMC Member

  • GMC Member
  • 321 posts
  • Version:GM:Studio

Posted 01 April 2012 - 02:37 AM

~~
  • 0

#3 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14392 posts
  • Version:GM:Studio

Posted 01 April 2012 - 03:57 AM

probably forgot to close the file...
  • 0

#4 Tzunami

Tzunami

    GMC Member

  • GMC Member
  • 321 posts
  • Version:GM:Studio

Posted 01 April 2012 - 04:07 AM

Close file is in another event, and the error occurs when the creation code of this object is ran (which is the code I included in the first post). Also the error message for the above code reads: "Error opening file for reading."

Will try putting the read and write in different objects. Sigh even if it works so much for clean code :(

Edited by Tzunami, 01 April 2012 - 04:18 AM.

  • 0

#5 Tzunami

Tzunami

    GMC Member

  • GMC Member
  • 321 posts
  • Version:GM:Studio

Posted 01 April 2012 - 04:36 AM

~~
  • 0

#6 Desert Dog

Desert Dog

    GMC Member

  • Global Moderators
  • 6409 posts
  • Version:Unknown

Posted 01 April 2012 - 04:48 AM

Please don't post again, after just 30 minutes..! Remember, other people are needing help, too.

Icuurd is right, you forgot to close the file you opened to write, before opening the other file to read.

user = get_string("Enter username:","");
map = file_text_open_write(user +".txt");
file_text_close(map);
contents = file_text_open_read(user +".txt");
show_message(file_text_readln(contents));
file_text_close(contents);


Although.. if you open a file for writing, then write nothing, your text file will just be blank! (even if it was filled up before)
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users