SRL Archive - Senior Scripts and Snippets

SaveUs - Bug


shaunthasheep

2007-08-02 14:36:29

I'm fixing Santa's runtime errors in a form he is going to use for a new script,
and i noticed saveus was saving the same thing for integer1 and boolean1 for every player, so I did so sniffing around and found it has [currentplayer] for the integer1-boolean1-etc1 type stuff, when it should be [f] if im right, see

{*******************************************************************************
procedure SaveUs;
By: Yakman
Description: Saves users from the player array into the chars file
*******************************************************************************}

procedure SaveUs;
var
f, CharsFile: Integer;
begin
if (FileName = '') then FileName := 'Chars';
CharsFile := RewriteFile(AppPath + FileName + '.dat', False);
for f := 0 to GetArrayLength(players) - 1 do
begin
WriteFileString(charsfile, 'name' + IntToStr(f) + '=' + players[f].name +
Chr(13));
WriteFileString(charsfile, 'pass' + IntToStr(f) + '=' + players[f].pass
+ Chr(13));
WriteFileString(charsfile, 'nick' + IntToStr(f) + '=' + players[f].nick
+ Chr(13));
WriteFileString(charsfile, 'active' + IntToStr(f) + '=' +
BoolToStr(players[f].active) + Chr(13));
if (FormOption[0]) then
WriteFileString(charsfile, 'loc' + IntToStr(f) + '=' +
players[currentplayer].loc + Chr(13));
if (FormOption[1]) then
WriteFileString(charsfile, 'skill' + IntToStr(f) + '=' +
players[currentplayer].skill + Chr(13));
if (FormOption[2]) then
WriteFileString(charsfile, 'waittime' + IntToStr(f) + '=' +
IntToStr(players[currentplayer].waittime) + Chr(13));
if (FormOption[3]) then
WriteFileString(charsfile, 'fight' + IntToStr(f) + '=' +
BoolToStr(players[currentplayer].fight) + Chr(13));
if (FormOption[4]) then
WriteFileString(charsfile, 'boolean1' + IntToStr(f) + '=' +
BoolToStr(players[currentplayer].boolean1) + Chr(13));
if (FormOption[5]) then
WriteFileString(charsfile, 'boolean2' + IntToStr(f) + '=' +
BoolToStr(players[currentplayer].boolean2) + Chr(13));
if (FormOption[6]) then
WriteFileString(charsfile, 'boolean3' + IntToStr(f) + '=' +
BoolToStr(players[currentplayer].boolean3) + Chr(13));
if (FormOption[7]) then
WriteFileString(charsfile, 'integer1' + IntToStr(f) + '='
+ IntToStr(players[currentplayer].integer1) + Chr(13));
if (FormOption[8]) then
WriteFileString(charsfile, 'integer2' + IntToStr(f) + '='
+ IntToStr(players[currentplayer].integer2) + Chr(13));
if (FormOption[9]) then
WriteFileString(charsfile, 'integer3' + IntToStr(f) +
'=' + IntToStr(players[currentplayer].integer3) +
Chr(13));
if (FormOption[10]) then
WriteFileString(charsfile, 'integer4' + IntToStr(f)
+
'=' + IntToStr(players[currentplayer].integer4) +
Chr(13));
if (FormOption[11]) then
WriteFileString(charsfile, 'string1' + IntToStr(f)
+ '=' + players[currentplayer].string1 + Chr(13));
if (FormOption[12]) then
WriteFileString(charsfile, 'string2' +
IntToStr(f) + '=' +
players[currentplayer].string2 + Chr(13));
if (FormOption[13]) then
WriteFileString(charsfile, 'string3' +
IntToStr(f) + '=' +
players[currentplayer].string3 + Chr(13));
if (FormOption[14]) then
WriteFileString(charsfile, 'extended1' +
IntToStr(f) + '=' +
FloatToStr(players[currentplayer].extended1)
+ Chr(13));
if (FormOption[15]) then
WriteFileString(charsfile, 'extended2' +
IntToStr(f) + '=' +
FloatToStr(players[currentplayer].extended2) + Chr(13));
if (FormOption[16]) then
WriteFileString(charsfile, 'extended3' +
IntToStr(f) + '=' +
FloatToStr(players[currentplayer].extended3) + Chr(13))
WriteFileString(charsfile, Chr(13));
end;
CloseFile(CharsFile);
end;

i got this to work -

{*******************************************************************************
procedure SaveUs;
By: Yakman, tiny mistake fixed by t.rs.m.
Description: Saves users from the player array into the chars file
*******************************************************************************}

procedure SaveUs;
var
f, CharsFile: Integer;
begin
if (FileName = '') then FileName := 'Chars';
CharsFile := RewriteFile(AppPath + FileName + '.dat', False);
for f := 0 to GetArrayLength(players) - 1 do
begin
WriteFileString(charsfile, 'name' + IntToStr(f) + '=' + players[f].name +
Chr(13));
WriteFileString(charsfile, 'pass' + IntToStr(f) + '=' + players[f].pass
+ Chr(13));
WriteFileString(charsfile, 'nick' + IntToStr(f) + '=' + players[f].nick
+ Chr(13));
WriteFileString(charsfile, 'active' + IntToStr(f) + '=' +
BoolToStr(players[f].active) + Chr(13));
if (FormOption[0]) then
WriteFileString(charsfile, 'loc' + IntToStr(f) + '=' +
players[f].loc + Chr(13));
if (FormOption[1]) then
WriteFileString(charsfile, 'skill' + IntToStr(f) + '=' +
players[f].skill + Chr(13));
if (FormOption[2]) then
WriteFileString(charsfile, 'waittime' + IntToStr(f) + '=' +
IntToStr(players[f].waittime) + Chr(13));
if (FormOption[3]) then
WriteFileString(charsfile, 'fight' + IntToStr(f) + '=' +
BoolToStr(players[f].fight) + Chr(13));
if (FormOption[4]) then
WriteFileString(charsfile, 'boolean1' + IntToStr(f) + '=' +
BoolToStr(players[f].boolean1) + Chr(13));
if (FormOption[5]) then
WriteFileString(charsfile, 'boolean2' + IntToStr(f) + '=' +
BoolToStr(players[f].boolean2) + Chr(13));
if (FormOption[6]) then
WriteFileString(charsfile, 'boolean3' + IntToStr(f) + '=' +
BoolToStr(players[f].boolean3) + Chr(13));
if (FormOption[7]) then
WriteFileString(charsfile, 'integer1' + IntToStr(f) + '='
+ IntToStr(players[f].integer1) + Chr(13));
if (FormOption[8]) then
WriteFileString(charsfile, 'integer2' + IntToStr(f) + '='
+ IntToStr(players[f].integer2) + Chr(13));
if (FormOption[9]) then
WriteFileString(charsfile, 'integer3' + IntToStr(f) +
'=' + IntToStr(players[f].integer3) +
Chr(13));
if (FormOption[10]) then
WriteFileString(charsfile, 'integer4' + IntToStr(f)
+
'=' + IntToStr(players[f].integer4) +
Chr(13));
if (FormOption[11]) then
WriteFileString(charsfile, 'string1' + IntToStr(f)
+ '=' + players[f].string1 + Chr(13));
if (FormOption[12]) then
WriteFileString(charsfile, 'string2' +
IntToStr(f) + '=' +
players[f].string2 + Chr(13));
if (FormOption[13]) then
WriteFileString(charsfile, 'string3' +
IntToStr(f) + '=' +
players[f].string3 + Chr(13));
if (FormOption[14]) then
WriteFileString(charsfile, 'extended1' +
IntToStr(f) + '=' +
FloatToStr(players[f].extended1)
+ Chr(13));
if (FormOption[15]) then
WriteFileString(charsfile, 'extended2' +
IntToStr(f) + '=' +
FloatToStr(players[f].extended2) + Chr(13));
if (FormOption[16]) then
WriteFileString(charsfile, 'extended3' +
IntToStr(f) + '=' +
FloatToStr(players[f].extended3) + Chr(13))
WriteFileString(charsfile, Chr(13));
end;
CloseFile(CharsFile);
end;

EDIT: im using the fix in santas form, incase someone thinks he can see this board, he cant.