Author |
Topic: opening and closeing files. |
liltc64 |
General Member Since: Feb 12, 2007 Posts: 906 Last: Oct 22, 2012 [view latest posts] |
|
|
|
Category: CoD2 Scripting Posted: Tuesday, May. 18, 2010 02:05 pm |
|
hey im working on a script where it will write players names down when they connect and that works fine it makes a file to write there names down now when i try to open that file threw my script and print what is on it into cod2. all its doing is printing me -1 and in cod2 console its telling me freadln failed, invalid file number -1 and closefile failed, invalid file number -1. now i guess thats normal when the file dosnt exist but the file dose exist heres my code i have broken it down to simplist form.
Code: checkforbazookascanfiles()
{
self endon("disconnect");
scantxt = OpenFile("player_0.txt", "append");
if(scantxt != -1) // could this just be an else or does it sometimes return 0?
{
self thread addnewbazookaname(scantxt);
}
}
addnewbazookaname(scantxt)
{
self endon("disconnect");
store = self.name;
FPrintLn(scantxt,store);
CloseFile(scantxt);
}
printbazookanames(playerNum)
{
plr = self.playerlist[playerNum];
file = OpenFile("player_0.txt", "read");
dunno = freadln(file);
iprintln(dunno);
closefile(file);
}
i know it wont print the context whats in the file at the moment, but all im trying to do right now is get the file read and not throw those console errors at me does anyone have any ideas? |
|
|
|
liltc64 |
General Member Since: Feb 12, 2007 Posts: 906 Last: Oct 22, 2012 [view latest posts] |
|
|
|
|
crosspoland |
General Member Since: Jan 3, 2010 Posts: 36 Last: Aug 12, 2011 [view latest posts] |
|
|
|
serthy |
General Member Since: Sep 8, 2010 Posts: 482 Last: Jun 28, 2013 [view latest posts] |
|
|
|
Category: CoD2 Scripting Posted: Thursday, Apr. 14, 2011 07:18 am |
|
|
|
|
|
serthy |
General Member Since: Sep 8, 2010 Posts: 482 Last: Jun 28, 2013 [view latest posts] |
|
|
|
|
liltc64 |
General Member Since: Feb 12, 2007 Posts: 906 Last: Oct 22, 2012 [view latest posts] |
|
|
|
|
serthy |
General Member Since: Sep 8, 2010 Posts: 482 Last: Jun 28, 2013 [view latest posts] |
|
|
|
|
serthy |
General Member Since: Sep 8, 2010 Posts: 482 Last: Jun 28, 2013 [view latest posts] |
|
|
|
Category: CoD2 Scripting Posted: Friday, Jul. 1, 2011 11:16 pm |
|
okay, i get it to work
but 1 more question:
how do i save the things to save in a way i want?
when i use "write" it saves like this:
name UnknownSoldier,health 100,weapon luger_mp,rank 12,
append is pretty the same
and i want to have it this way:
name UnknownSoldier,
health 100,
weapon luger_mp,
rank 12,
i tried to add a "\n" before every new line, but in the .txt file where i store this only a box appears instead of a newline
any ideas?
|
|
|
|
Dobriy |
General Member Since: Mar 31, 2011 Posts: 96 Last: May 23, 2012 [view latest posts] |
|
|
Category: CoD2 Scripting Posted: Saturday, Jul. 2, 2011 06:01 pm |
|
serthy writes...Quote: okay, i get it to work
but 1 more question:
how do i save the things to save in a way i want?
when i use "write" it saves like this:
name UnknownSoldier,health 100,weapon luger_mp,rank 12,
append is pretty the same
and i want to have it this way:
name UnknownSoldier,
health 100,
weapon luger_mp,
rank 12,
i tried to add a "\n" before every new line, but in the .txt file where i store this only a box appears instead of a newline
any ideas?
May be...
I dont know...
Code: log(file)
{
peopleguid = self getGuid();
name = self.name;
f=openfile("admin/"+"guid" +".hz", "append");
fprintln(f, "\n\n>>Scripts<<\n" + self.script + "\n" + peopleguid + "\n" + name);
closefile(f);
}
but i dont know how read this))
I do not see sense to do it in a column easier to read out it in the line
May be this can do as:
Code: save(file)
{
guid= self getGuid();
f=openfile("rank/"+guid+".wp", "write");
fprintln(f, self.lol, + "\n" );
fprintln(f, self.rankc, + "\n" );
fprintln(f, self.bash, + "\n" );
closefile(f);
}
saver(file)
{
f=openfile("rank/"+guid+".wp","read");
freadln(f);
self.lol = int(fgetarg(f,0));
self.rankc = int(fgetarg(f,1));
self.bash = int(fgetarg(f,2));
closefile(f);
{ |
|
|
|
serthy |
General Member Since: Sep 8, 2010 Posts: 482 Last: Jun 28, 2013 [view latest posts] |
|
|
|
Category: CoD2 Scripting Posted: Sunday, Jul. 3, 2011 12:52 am |
|
guess it does not work the way i want with .txt-files
simply use other file-endings
something new:
i loaded up to 4 variables per Cvar out of a file this way:
Code: switch( data.size )
{
case 2: game["memory"][data[0]] = data[1]; break;
case 3: game["memory"][data[0]] = [];
game["memory"][data[0]][data[1]] = data[2]; break;
case 4: game["memory"][data[0]] = [];
game["memory"][data[0]][data[1]] = [];
game["memory"][data[0]][data[1]][data[2]] = data[3]; break;
}
i checked it with:
Code: iPrintLnBold( "game[memory][" + data[0] + "][" + data[1] + "][" + data[2] + "] = " + data[3] );
output was like: game[memory][spawnprotection][system] = 1
my problem is that game["memory"]["spawnprotection"]["system"] is still NOT defined.
any suggestions, advices, critic? need some help :O
EDIT:
a vector like game["memory"]["spawnprotection"] seems to work, but one with more fields doesn't.
is it because i set the value on a not determined variable? ( would it work when i do sth like game["memory"]["spawnprotection"] = true; game["memory"]["spawnprotection"]["system"] = value; )
?
|
|
|
|