Hi, and thanks for your responses ahead of time. I am new to fileObjects, and have been trying to make a function that can save strings of data, preceeded by an identifying number, and another function that can find a string by that identifying number.
For example, if I wanted the text document to read as follows:702 wharrgarbl
62 lemon pie
4901 taco bell mascot
7 new mexico
How would I check to see if a line that started with 4901 already existed, so I could replace it with "4901 taco bell mascot" in case it read something different?
This was my attempt at this:function savedata(%id, %data)
{
%file = new fileobject();
%file.openforwrite("config/server/randomtest.txt");
while(!%file.isEOF())
{
%line = %data.readline();
if(getword(%line, 0) $= %id)
{
echo("data found, overwriting...");
%file.writeline(%id TAB %data);
%found = true;
}
}
if(!%found)
{
echo("data does not exist! creating...");
%file.writeline(%id TAB %data);
}
%file.close();
%file.delete();
}
However, this code just keeps overwriting the first line, and I'm not sure how to fix it, or where to start for the LoadData function that would go with it.