Windows [SOLVED] file_text_writeln not working

W

Wraithious

Guest
Hi, I've been fighting with this for 3 days and can't figure it out, basically I have a text file that holds user inputted strings, which are read and shown on the game screen. for some reason all of the inputted strings from my array get put on the first line in the file, not the end of the line either, every new index of the array gets put at the beginning of the line! how is that even possible?????? If it's the first text being saved it works normally because that is done seperatly. Heres the code to what I have:

This script is run at game beginning, then called after adding text to update the game screen-
Script getinfo:
Code:
if(argument[0]=0)
{
var findit="top"+string(global.forum);
if(file_exists(working_directory+"\"+findit+".txt"))//load the topics, get how many blocks and topics
{
var num=0;
gtfile=file_text_open_read(working_directory+"\"+findit+".txt");
while(!file_text_eof(gtfile))
{
global.blocks[global.forum]=floor(num*(1/14));
global.topstr1[num]=file_text_read_string(gtfile);//Get each line of text from the file
global.topic[global.forum]=num;//get how many lines of text that are in the file
file_text_readln(gtfile);
num+=1;
}
file_text_close(gtfile);
}
}
Step event:
Code:
if global.bchoi=4 && string_width(keyboard_string)<=632 global.topstr1[(global.topic[global.forum]+1)]=keyboard_string;//get new topic text
Alarm event:
Code:
if(global.bchoi=4)
{
var datim=date_datetime_string(date_current_datetime());//get the headder info and open the file to write to
var memid="";
if global.memli=1 memid=global.guest;
if global.memli>1 memid=global.memna[global.memli];
finder="top"+string(global.forum);
setget=file_text_open_write(working_directory+finder+".txt");
if(global.topstr1[0] !="")
{
for(i=0;i<(global.topic[global.forum]+1);i+=1;)
{
file_text_write_string(setget,("Post by "+memid+" "+datim+"#"+global.topstr1[i]));
file_text_writeln(setget);//This is not working at all, it writes every index of topstr1[i] to the first line in the text file
}
file_text_close(setget);
}
if(global.topstr1[0] ="")
{
file_text_write_string(setget,("Post by "+memid+" "+datim+"#"+keyboard_string));
file_text_close(setget);
}
getinfo(0);//call the getinfo script to update how many topics there are
}
I have tried so many different combinations of things and nothing seems to work, any help with what I'm doing wrong would greatly be appreciated!
 
W

whale_cancer

Guest
My only thought is that you should be using file_text_open_append instead of file_text_open_write, as you seem to be writing to the text file in different places, instead of all at once (I assume you write it all at once when you save it, and that is why it is working there).
 
W

Wraithious

Guest
you seem to be writing to the text file in different places
That alarm event is the only place that writes to the file, if the file is blank it writes the first line, if it's not then it writes the array but write_ln isnt working, i cant figure out why, i will try the append sugestion but I thought that function just adds text to the last line in the file?
 
W

Wraithious

Guest
My only thought is that you should be using file_text_open_append instead of file_text_open_write
Yep that did the trick, I changed it to append and it works great thank you very much!

Code:
if(global.topstr1[0] !="")
{
setget=file_text_open_append(working_directory+finder+".txt");
file_text_writeln(setget);
file_text_write_string(setget,"Post by "+memid+" "+datim+"#"+keyboard_string);
file_text_close(setget);
}
 
W

whale_cancer

Guest
That alarm event is the only place that writes to the file
Yeah, even though it is in only one place in the code, it is being triggered at different points in the game. Glad that worked for you. File handling is something I went on a rampage about a few months ago as studio's file handling is so much more inconvenient than 8's.
 
Top