Author Topic: Filewriting loopcheck and rewrite  (Read 623 times)

I have a clientsided database chat mod, and i need one more thing
I want to, before making the variable, scan the file for the variable being set...
I found how to scan a file elsewhere, but i can't figure out how to find the variable.

So i need to know how to:

A. Scan the file for a certain line. I worked this out, but i REALLY need to know how to write over a line.
B. If the line is found, then it will overwrite the variable on THAT LINE ONLY, nothing else.
C. If it isn't, append the new variable to the bottom of the file(I can do this)

Can someone please answer?
« Last Edit: August 26, 2010, 04:58:20 PM by ThinkInvisible »

I think you can use this
Code: [Select]
function whatever(%input) //Input is the name of your variable you want changed
{
//fileobjectcreated
//fileobjectopenforwrite
//tolazytodoit
while(!%file.isEOF())
{
%line = %file.readLine();
if(getSubStr(%line,0,1) $= "$")
if(getSubStr(getWord(%line,0),0,strLen(getWord(%line,0))/2) $= strLen(%input)/2)
{
%file.writeLine(%changevariabletowhatever);
break;
}
}
}

I haven't tested it, but i hope the theory of this can help you, or if someone actually knows how to do it a more efficient way, correct me.
« Last Edit: August 26, 2010, 09:21:40 PM by Syntax »

I think you can use this
Code: [Select]
function whatever(%input) //Input is the name of your variable you want changed
{
//fileobjectcreated
//fileobjectopenforwrite
//tolazytodoit
while(!%file.isEOF())
{
%line = %file.readLine();
if(getSubStr(%line,0,1) $= "$")
if(getSubStr(getWord(%line,0),0,strLen(getWord(%line,0))/2) $= strLen(%input)/2)
{
%file.writeLine(%changevariabletowhatever);
break;
}
}
}

I haven't tested it, but i hope the theory of this can help you, or if someone actually knows how to do it a more efficient way, correct me.
I think I have a more efficient way, but I don't know if it works.

I think you can use this
Code: [Select]
function whatever(%input) //Input is the name of your variable you want changed
{
//fileobjectcreated
//fileobjectopenforwrite
//tolazytodoit
while(!%file.isEOF())
{
%line = %file.readLine();
if(getSubStr(%line,0,1) $= "$")
if(getSubStr(getWord(%line,0),0,strLen(getWord(%line,0))/2) $= strLen(%input)/2)
{
%file.writeLine(%changevariabletowhatever);
break;
}
}
}

I haven't tested it, but i hope the theory of this can help you, or if someone actually knows how to do it a more efficient way, correct me.
That doesn't really work for what i need, as:
-What i REALLY needed, was how to rewrite just that line, even if it is midfile, with a new line.
EDIT : And now that i study the script more closely, wouldn't that make an infinite loop that crashes you? Because i see no incrementing command.
« Last Edit: August 26, 2010, 11:56:16 PM by ThinkInvisible »

Is it even possible to do what i need done?

export("$variable with *s for wildcards", "path", 0);

I think you can use this
Code: [Select]
function whatever(%input) //Input is the name of your variable you want changed
{
//fileobjectcreated
//fileobjectopenforwrite
//tolazytodoit
while(!%file.isEOF())
{
%line = %file.readLine();
if(getSubStr(%line,0,1) $= "$")
if(getSubStr(getWord(%line,0),0,strLen(getWord(%line,0))/2) $= strLen(%input)/2)
{
%file.writeLine(%changevariabletowhatever);
break;
}
}
}

I haven't tested it, but i hope the theory of this can help you, or if someone actually knows how to do it a more efficient way, correct me.

That is entirely wrong and will not work, don't bother posting if you don't know how to do something - it'll just confuse people trying to learn.

EDIT : And now that i study the script more closely, wouldn't that make an infinite loop that crashes you? Because i see no incrementing command.

::readLine() moves the file pointer of the file object, and ::isEOF() checks whether the pointer has reached the end of the file.

Regardless, you shouldn't be re-writing an entirely new file each time someone makes a change in this database - file handling is a lot of overhead. You should be keeping most/all of the db in memory and saving it to a flatfile db at intervals.

Got some major help from a friend, apparently i can just use export...

Got some major help from a friend, apparently i can just use export...

Quick note: Careful not to accidentally put in code to export into a .zip. It causes annoying errors you can't easily fix, only patch, at least on XP.