Author Topic: Writing to a file  (Read 932 times)

Okay, Well this is semi-working, If i delete the file i can write a name to it, but after i write the first one it doesn't work anymore.
Code: [Select]
function ClientCmdAddToDataBase(%c,%Msg)
{
%i = 0;
while(%i < NPL_List.RowCount())
{
if(getWord(%msg,0) $= getField(NPL_List.getRowText(%i),1))
%dba = getField(NPL_List.getRowText(%i),1) SPC getField(NPL_List.getRowText(%i),3);
%i += 1;
}
%file = new FileObject();
if(!isFile("Config/Client/DataBase.txt"))
{
%file.openForWrite("Config/Client/DataBase.txt");
%file.writeLine("DataBase");
%file.close();
}
%file.openForAppend("Config/Client/DataBase.txt");
%file.writeLine(%dba);
%file.close();
%file.delete();
CommandToServer('MessageSent',getWord(%dba,0) SPC "[BL_ID:" SPC getWord(%dba,1) @ "] was added to my database.");
}
If you notice somthing out of the ordinary, its probably because i had this in a switch and just put it in a function.
EDIT: Fixed indentation
« Last Edit: November 23, 2008, 05:57:35 PM by Slicksilver555 »

Thats the most handicapped indentation i've ever seen.

It got messed up by the paste, and thanks alot for the help, ephi.

This is working fine for me:

Code: [Select]
function ClientCmdAddToDataBase(%c,%msg)
{
%dba = "";
for(%i=0;%i<NPL_List.RowCount();%i++)
{
if(getWord(%msg,0) $= getField(NPL_List.getRowText(%i),1))
{
%dba = getField(NPL_List.getRowText(%i),1) SPC getField(NPL_List.getRowText(%i),3);
break;
}
}
if(%dba!$="")
{
if(!isFile("Config/Client/DataBase.txt"))
{
%file = new FileObject();
%file.openForWrite("Config/Client/DataBase.txt");
%file.writeLine("DataBase");
%file.close();
%file.delete();
}
%file = new FileObject();
%file.openForAppend("Config/Client/DataBase.txt");
%file.writeLine(%dba);
%file.close();
%file.delete();
CommandToServer('MessageSent',getWord(%dba,0) SPC "[BL_ID:" SPC getWord(%dba,1) @ "] was added to my database.");
}
}

I just changed a few things around.
Not sure why it wasn't working for you though.

It got messed up by the paste, and thanks alot for the help, ephi.

I don't think it did, otherwise those brackets would be atleast a space away from the edge. Anyway, You haven't even asked the question in proper English. All I can ascertain from your post is that you're deleting a file then trying to write a name to it, but it won't.

And just as a point of courtesy, you don't need to spam the inhabitants of the server each time someone joins to let them know you have some cigarettegio script to log their ID and Name.


Nope, Truce, Didn't work.


Eh? Worked perfectly for me.
Well, I tested this in a function, not a ClientCmd.

That's the only difference I could think of if you didn't modify it any.

I have it in a switch, based off a clientCmd, its for CCB, You've seen it.
Code: [Select]
package CCB
{
function ClientCmdChatMessage(%c,%a,%b,%fmsg,%cs,%name,%cp,%msg)
{
if(getWord(%msg,0) $= "CCB")
{
switch$(getWord(%msg,1)
{
//Bunch of functions
case "addToDataBase":
//TheCode
}
}
}
};
activatePackage(CCB);
EDIT: Thats not all the code, i have trust systems and blocking systems in there too.
« Last Edit: November 24, 2008, 01:17:36 PM by Slicksilver555 »

I don't think it did, otherwise those brackets would be atleast a space away from the edge. Anyway, You haven't even asked the question in proper English. All I can ascertain from your post is that you're deleting a file then trying to write a name to it, but it won't.

And just as a point of courtesy, you don't need to spam the inhabitants of the server each time someone joins to let them know you have some cigarettegio script to log their ID and Name.
I'm not logging Everyone's name and BL_ID, I'm logging who's IDs might be useful in the future.

I have it in a switch, based off a clientCmd, its for CCB, You've seen it.
Code: [Select]
package CCB
{
function ClientCmdChatMessage(%c,%a,%b,%fmsg,%cs,%name,%cp,%msg)
{
if(getWord(%msg,0) $= "CCB")
{
switch$(getWord(%msg,1)
{
//Bunch of functions
case "addToDataBase":
//TheCode
}
}
}
};
activatePackage(CCB);
EDIT: Thats not all the code, i have trust systems and blocking systems in there too.

Code: [Select]
switch$(getWord(%msg,1)
Well you're missing a parenthesis there...

And this is in a client.cs, correct?


What do you mean by no?
Code: [Select]
switch$(getWord(%msg,1) Two open, one closed
Code: [Select]
switch$(getWord(%msg,1)) Two open, two closed

sorry, I must have been daydreaming, I meant yes.