Author Topic: [Solved] [Stupid Question] File Input/Output Help?  (Read 788 times)

Hey guys, so I have this code:
Code: [Select]
function servercmdWriteFile(%filename, %input)
{
%filename = new FileObject();
%filename.OpenForAppend("Add-Ons/script_Testing/filewrite.cs");
%filename.writeLine(%input);
%filename.close();
%filename.delete();
echo("You wrote in the file.");
}

function servercmdReadFile(%filename)
{
%filename = new FileObject();
%filename.OpenForRead("Add-Ons/script_Testing/filewrite.cs");
while(!%filename.isEOF())
{
announce("Lines You've Read:" SPC %lineCt);
%lineCt++;
announce(%filename.ReadLine());
}
announce("In total, you've read" SPC %lineCt SPC "line(s).");
%filename.close();
%filename.delete();
}

I want to be able to modify a file ingame, using the servercmds I set up. It's working fine when I do the read command:



...but, how do I make it so this data is stored to a text/.cs document? At the bottom of the tutorial I was using, it said that the command save(object, file); could be used to save to a file. I have no idea how to use this, though.
Code: [Select]
function servercmdWriteFile(%filename, %input)
{
%filename = new FileObject();
%filename.OpenForAppend("Add-Ons/script_Testing/filewrite.cs");
%filename.writeLine(%input);
save(%filename, "Add-Ons/script_Testing/filewrite.cs");
%filename.close();
%filename.delete();
echo("You wrote in the file.");
}
is far from working.

Am I misunderstanding the whole thing completely, or do I just not know how to use that command?
« Last Edit: January 01, 2015, 04:02:12 PM by Johnny Blockhead »

When you open a file for writing or appendage, it automatically makes it into a file for you..

If you attempt to write to a file that does not exist blockland will create one automatically.

Well first off you don't need to do %filename = new fileObject(); as that is pointless, but rather you should do %file = new fileObject(); and instead use %file.OpenForAppend("blahblah/" @ %fileName @ ".cs"); another thing to note is that it is far better to create/write to a directory in the config, rather than an add-on, that way you're not trying to write in a compressed directory.