Blockland Forums > Modification Help
How do I add an item, delete an item, and get an item from a text file?
(1/3) > >>
Axolotl:
How? I've seen mutemod's list manager but it doesn't save to a text file.
Ipquarx:
you must be talking about FileObjects.
It allows you to write, read, and create/delete files.

to add a item, heres the syntax, but there are 2 different modes for writing; Write and Append.
Write clears the file and then writes lines.
Append opens the file and writes to the end of the file.
--- Code: ---%blah = new FileObject();
%blah.openForWrite("filepath");
%blah.writeLine("enter text here");
%blah.close();
%blah.delete();
--- End code ---
Thats to overwrite.
And to append:
--- Code: ---%blah = new FileObject();
%blah.openForAppend("filepath");
%blah.writeLine("enter text here");
%blah.close();
%blah.delete();
--- End code ---
To read, its the same thing, just change a couple things:
--- Code: ---%blah = new FileObject();
%blah.openForRead("filepath");
%blah.readLine();
%blah.close();
%blah.delete();
--- End code ---
Axolotl:

--- Quote from: Ipquarx on December 19, 2011, 06:33:17 PM ---you must be talking about FileObjects.
It allows you to write, read, and create/delete files.

-code-
--- End quote ---
Thanks, I'll edit when it doesn't work.
Axolotl:
Wait, what if there is no text file and I need the add-on to create it? In that case, I also need a script to check if the file exists.
cheese6:

--- Quote from: Axolotl on December 19, 2011, 06:41:41 PM ---Wait, what if there is no text file and I need the add-on to create it? In that case, I also need to check if the file exists.

--- End quote ---
When using the FileObject functions, the openForWrite will create the file, so will the openToAppend (I think).
To check if there is a file, do
if(isFile(%path))
{
//yes
}
else
{
//no
}

Enjoi.
Navigation
Message Index
Next page

Go to full version