Author Topic: FileObjects - Saving and Loading Data  (Read 1365 times)

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:
Code: [Select]
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:
Code: [Select]
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.

Wait, why are you trying to write yet are attempting you read at the same time?

Wait, why are you trying to write yet are attempting you read at the same time?

I am attempting to find and replace a line that is identified by the first word on that line.

Using an FO to manage data is a horrendous idea.

Using an FO to manage data is a horrendous idea.
This.

Use ScriptObjects to store data.

I want the data to still be available after the server has closed.  If I do use a script object, I will have to come back to this anyway.

I am trying to understand Iban's cityRPG saving system, but it is one of the most complicated pieces of code I have ever tried to make sense of.

I did not write Sassy.

I want the data to still be available after the server has closed.  If I do use a script object, I will have to come back to this anyway.

I am trying to understand Iban's cityRPG saving system, but it is one of the most complicated pieces of code I have ever tried to make sense of.
If you use that list above you easily use script objects for this.
Set the values like SO.value[4109] = "taco bell mascot";
Then to save it just call SO.save(filePath);
And then execute saved file.

If you use that list above you easily use script objects for this.
Set the values like SO.value[4109] = "taco bell mascot";
Then to save it just call SO.save(filePath);
And then execute saved file.

I think this would work better with arrays and exporting, or am I misunderstanding what you are suggesting?

is ::save(%filepath) a default function or something I need to write, because that is pretty much what I have been trying to do, but not succeeding.

::save is a default function for all object types.

ConsoleObject.save("config/test.txt");

alright.  I tested this, and it just makes a code to re create the scriptobject.  I assume this must be put into a .cs file, so I think I am good for now, unless someone has a last minute suggestion before I lock.

Ya I have a suggestion, don't lock coding help topics.

Someone may have a question and not want to create a topic.

Ya I have a suggestion, don't lock coding help topics.

Someone may have a question and not want to create a topic.

Ok.  I wasn't really planning on locking, especially because I never really found out what I wanted to know about fileObjects, but found a different approach to get where I needed.

Store the data in a script object and THEN write it out.
Here's a database system I made and I've used for DRPG (which never had corrupted data, fyi):
http://dl.dropbox.com/u/551734/blockByte.cs
And here's the example for using it:
http://dl.dropbox.com/u/551734/blockByteExample.txt
EDIT: The exception system is kinda useless on it. If you'd like to me to remove it just say.
EDITEDIT: It can load CSV and a format I wrote. It can export CSV, XML, SQL and the format I wrote.
« Last Edit: April 11, 2011, 04:07:06 AM by Destiny/Zack0Wack0 »

Store the data in a script object and THEN write it out.
Here's a database system I made and I've used for DRPG (which never had corrupted data, fyi):
http://dl.dropbox.com/u/551734/blockByte.cs
And here's the example for using it:
http://dl.dropbox.com/u/551734/blockByteExample.txt
EDIT: The exception system is kinda useless on it. If you'd like to me to remove it just say.
EDITEDIT: It can load CSV and a format I wrote. It can export CSV, XML, SQL and the format I wrote.
this really isn't that good.

and bragging that it has never had "corrupted data" is silly because even Sassy never corrupted anything.

it would be like an engineer bragging "btw my elevators have never fallen 20 stories."