Author Topic: File Writing help needed.  (Read 1763 times)

Okay, Well im making a small script because on my server when it crashes, my Auto Admin list is cleared and i dont know their ID's to re-auto them. I have nothing to call it so i call it the friend list- And, No, it does not tell what server the persons on, Thats impossible, And, No, it does not tell if the person is playing. That is also impossible, Now for the script.

Code: [Select]
function ServerCmdClearFriends(%Client)
{
         %file = new FileObject();
         %File.openForWrite("Add-Ons/Frendlist.Friends");
         %File.close();
         %File.Delete();
}
function ServerCmdAddFriend(%Client,%Name,%ID)
{
         Echo("Stage -1 Complete");
         Echo("Stage -2 Complete");
                  %file = new FileObject();
         Echo("Stage -3 Complete");
                  %file.openForAppend("Add-Ons/Friendlist.Friends");
         Echo("Stage -4 Complete");
                  %file.Writeline(%Name SPC %ID);
         Echo("Stage -5 Complete");
                  %file.close();
         Echo("Stage -6 Complete");
                  %File.Delete();
         Echo("Stage 1 Complete");
}
function ServerCmdViewFrends(%Client)
{
         %file = new FileObject();
                  %file.openForRead("add-ons/Friendslist.friends");
         while(!%file.isEOF())
{
                  %line = %file.readline();
                  %Lines++;
                  echo("Line" SPC %lines @ ":" SPC %Line);
}
         %file.close();
         %file.delete();
}

Oh, and the make the file part (clearfriends) works, its the rest that doesnt, And the echo's are for de-bugging, ill remove them later.
« Last Edit: July 19, 2008, 11:48:33 AM by Slicksilver555 »

Both "impossible" things listed are possible, but hard to set up.


Edit:

Looking over the script further,

%name and %id, the variables you're writing to the file, don't exist. You're pulling them out of thin air. The arguments on the function are just %arg1 %arg2 etc, nothing about %name or %id.


Also, in this echo
echo("Line", %lines,": ",%Line);
why are there commas? You should be using @ or SPC.
« Last Edit: July 18, 2008, 12:07:39 AM by rkynick »

Really, Well thats not even the point of the script, I asked for help, not critCIAm of my thoughts.

I edited in helpful stuff.



Ah, i see that now, But fixing the first thing wouldnt help, because i tryed changing the variables, but forgot to change the script, and if the second one did work, It would only fix one function.
Thanks for the help.

EDIT: This would be clientside, right? Just checking, i think it would be annoying if i find a friend and ID on another server and have to open up a single player to Add Them...
« Last Edit: July 18, 2008, 12:14:04 AM by Slicksilver555 »

Nope, Didnt help. Might have helped on the read part, I cant test untill i get the Write part working.

Fixing the first thing wouldn't help?

Son, lemme tell you about why writing null values to a text file is going to forget up your script.

Your text file!:
Quote from: text file




Lets load up our friends list now, shall we?

Quote from: echos
Line 1:
Line 2:
Line 3:
Line 4:

You have a lot of friends, dontcha.

Anyways, you can't declare servercmds clientside, use clientcmds, but then you cant use those as /cmds unless you write a package to override whatever chat things happen clientside. I suggest making %arg1 %name and %arg2 %ID. I'm not old enough to call you "Son". I don't care, however. Unless this is throwing a syntax error or some other stuff is going on that I'm not seeing, changing the %arg names should fix it.


Also "It would only fix one function" is a bad thing to live by, there's no panacea for scripting errors, so if you do your debugging like that, you'll get nothing fixed, instead of at least getting 1 or 2 things fixed.

How would
Ex:
Slicksilver555 1359
be a null value?
And im trying to figure out wrighting to the fie now, if i type in /addfriend Slicksilver555 1359 and it doesnt add, how am i supposed to figure out if the /viewfriends is working?
Also, ill fix the clientside/severside problem once it works on a listen server.
So, if anyone has any code to replace my code for non-working parts, Please post.

...

The variables you are writing don't exist, they are never defined, therefore, they are null values.


I'm saying you need to define them and your blatantly disregarding my advice.

I defined them in my script, then tested.it didnt work.

I defined them in my script, then tested.it didnt work.

Wow. Stupid AND stubborn.

Your serverCmdAddFriend takes the parameters %arg1 to 4, and you're writing %name and %id to the text file. Where is %name? Change %arg1 to %name and %arg2 to %id and you'll be ok.

i did change them, i just didnt bother editing my post to show the new script where %Name and %ID are defined.
Edit:
It still didnt work.
Changed post. Look at it now...
« Last Edit: July 19, 2008, 11:44:04 AM by Slicksilver555 »

Replace

Code: [Select]
%file.openForAppend("Add-Ons/Friendlist.Friends");
With

Code: [Select]
echo(%file.openForAppend("Add-Ons/Friendlist.Friends"));
And see what it echos. It could be your absurd file extension you're using.

It echoed:1
EDIT:
And i dont know what that means :/
« Last Edit: July 20, 2008, 10:49:52 AM by Slicksilver555 »

It echoing 1 just means that the open function is returning 1 to the echo.. so it is successfully opening the file.

However you might want to correct the filenames.

In the clearfriends function you're opening Frendlist.friends.
In the addfriend function you're opening Friendlist.friends.
And in the viewfriends function you're opening Friendslist.friends.