SRL Archive - Help and Support

Error with saving...


The_Shermanator

2008-11-02 23:38:41

Ok so im trying to have my script save the last progress report, which is the easy part. So I was looking at the way SRL writes stuff to files and I tried to copy it.

So I came up with…
Procedure SetupSaving;
begin
TheFileNumber := RewriteFile(AppPath + 'Shermanator''s Progress Reports.txt', True);
if TheFileNumber >= 0 then
WriteLn(' Found somewhere to save!');
end;

Procedure SaveAndWriteLN(Text: string);
begin
if(FinalProggy)then
begin
WriteFileString(TheFileNumber, text+#13#10);
WriteLn(Text);
end else
WriteLn(Text);
end;

And I suppose it writes it because I look to where it did and…when I try to open it, it says its in use by another program(scar).
Could anybody help?
EDIT: Once I close scar, it did what it was supposed to, but could anybody still help me stop it from using it after I'm done with it :EDIT

-Shermanator

EvilChicken!

2008-11-03 00:24:10

In my STILL-unfinished-flax spinner, I have this:


SetUp:

procedure FilesSetup;
var
Byt: Byte;

begin
Byt := 0;
if FileExists(AppPath + 'yourscriptsname Progress Report.txt') then
repeat
Inc(Byt);
until not FileExists(AppPath + 'yourscriptsname Progress Report (' + IntToStr(Byt) + ').txt');

if Byt > 0 then
ProgPath := AppPath + 'yourscriptsname Progress Report (' + IntToStr(Byt) + ').txt'
else ProgPath := AppPath + 'yourscriptsname Progress Report.txt';
end;


Actual saving:
procedure SaveToTxt;
var
X: Integer;

begin
try
X := ReWriteFile(ProgPath, False);
WriteFileString(X, GetDebugText);
CloseFile(X);
WriteLn('Progress report saved to: ' + ProgPath);
except
WriteLn('Saving progress report to file failed.');
end;
end;


Ofcourse, with ProgPath being a global variable.




So, call SaveToTxt whenever you've just cleared the debug and printed the progress report.
You see, this'll copy everything that is in the debug box, to the file.
And, I guess your porblem was that you forgot to use Closefile and got a memory leak.

The_Shermanator

2008-11-03 01:26:41

Thanks EvilChicken!
I didn't use your way, but I found my own way around it.
<3 Self learning lol
Rep++ for giving such an effort.

-Shermanator

Naum

2008-11-03 12:21:37

O Dear EC still using bytes.. What did uncle wizzup say :p. I had another Idea
Couldn't you use a between function to get the last lines.

E.g

Procedure Save;
Var S : String;
X : Integer;

Begin
Try
S := Between('Final Proggie :','END HERE', Lowercase(GetDebugText));
X := ReWriteFile(AppPath, False);
WriteFileString(X, S);
Finally
CloseFile(X);
WriteLn('Progress report saved to: ' + AppPath);
Except
WriteLn('Err0r Couldn'#39't save file');
end;
end;

Of course what you would need to do is once they terminate or the script is stopping make it writeln this:
e.g

Final Proggie :
[worked for 6 secs]
END HERE


Hence it would copy

[worked for 6 secs]
:)

Hope I Helped.

Ahh I see you got a solution