SRL Archive - OSR Help

adding a log at the end of script


rj

2013-03-12 20:28:33

hello,
i want to add a log of what the bot did at the end of the script, what type of variable would i have to store this in?

The Mayor

2013-03-12 20:30:48

Like how many times it banked or….?

rj

2013-03-12 20:35:08

From: The Mayor
Like how many times it banked or….?


example
opening bank
withdrawing
closing

of course it would have a timestamp

Le Jingle

2013-03-12 20:38:46


AddOnTerminate('ProgressReport');
if you're trying to record the debug of certain actions, record them in a variable, then call a procedure that prints them to console (i.e. like ProgressReport).
I think you mean the above?
I know some people like to make a separate procedure for a ``FinalReport,'' but I think they're one in the same.
-Lj

rj

2013-03-12 20:41:18

From: Le Jingle

AddOnTerminate('ProgressReport');
I think you mean the above?
I know some people like to make a separate procedure for a ``FinalReport,'' but I think they're one in the same.
-Lj




i already have that but i dont know how to make it print like a log of what the bot did

Ok now I'm on my computer so I can elaborate:

There would be a procedure like when it banks I would call

AddReport('Banking')

And when the user clicks stop script a log is printed on the writeln of everything the bot did like:


withdrawing
banking
fletching
waiting
waiting
fletching
waiting
banking
withdrawing

The Mayor

2013-03-12 20:53:53

Well I guess you could just add a debug procedure which prints the status to the debug box. In my script the output is something like:

We are taking a break in 0h 56m 32s
We have Oak Logs in our inventory
We are currently walking to the Sawmill (using SPS)
We found Planker Object DTM, walking there now
Walked to planker using ObjDTM
Searching for the Planker using TPAFinderPlanker
We found the Planker with TPAFinderPlanker
Waiting for the plank interface
We found the plank interface
We have Oak Planks in our inventory
We are currently walking to the Bank (using SPS)
Failed to find Bank Object DTM, finding symbol
Found Bank symbol, walking there now
Searching for the Banker using OpenBankNPCEx
Searching for the Banker using OpenBankFast
Found Banker using OpenBankFast
Depositing planks
Withdrawing logs
We have Oak Logs in our inventory
Potentially engaging in AntiBan
We are currently walking to the Sawmill (using SPS)


You could just add + TimeRunning if you want the time-stamp. I think this is what you mean. If you wanted to actually get the number of times each action was performed then you would have to assign each to a variable and increase it by 1 each time it was performed.

rj

2013-03-12 20:56:01

From: The Mayor
Well I guess you could just add a debug procedure which prints the status to the debug box. In my script the output is something like:



You could just add + TimeRunning if you want the time-stamp. I think this is what you mean. If you wanted to actually get the number of times each action was performed then you would have to assign each to a variable and increase it by 1 each time it was performed.


I don't want to do that as the script is running because it ruins the progress report :s I want it to print everything at the end, maybe to a file perhaps so users can show me it so I can find bugs better

EDIT: Sort of answered my question here:

Program Hi;
Procedure AddReport(Report:TStringArray);
Begin
Writeln('' + ToStr(Report))
End;
Begin
AddReport(['Banking']);
AddReport(['Withdrawing']);
AddReport(['Withdrawing']);
End.

But how do I make it Writethe timestamp like I can with writeln

SetScriptProp(SP_WriteTimeStamp, [True]);

Le Jingle

2013-03-12 21:00:27

Are you actually trying to save a file log of the script's action's during runtime?
see SRLlog.simba (/includes/srl/core/)

Sin

2013-03-12 21:00:44


const
DEBUG = True; //let the user set this.

procedure Debugln(s:String);
begin
if DEBUG then
writeLn(s);
end;


rj

2013-03-12 21:04:53

Actually nevermind after testing it it is only saving 1 string at a time

Program Hi;
Var
GlobalReport:String;
Procedure WriteReport;
Begin
Writeln('' + GlobalReport)
End;
Procedure AddReport(Report:TStringArray);
Begin
GlobalReport := ToStr(Report);
// Writeln('' + ToStr(Report))
End;
Begin
SetScriptProp(SP_WriteTimeStamp, [True]);
AddReport(['Banking']);
wait(1000)
AddReport(['Withdrawing']);
wait(1000)
AddReport(['Withdrawing']);
wait(1000)
WriteReport;
End.


EDIT:

I think I got it:

Program TestSave;
function OpenReportFile(): integer;
var
fileName,Bot_SavePath: string;
begin

Bot_SavePath := 'C:/Simba/'
if (not directoryExists(Bot_SavePath)) then
forceDirectories(Bot_SavePath);

// make sure it's a valid file name (Windows)
fileName := 'Fletcher Log.txt';
// fileName := replace(fileName, '/', '-');
//fileName := replace(fileName, ':', ' ');
fileName := Bot_SavePath + fileName;

try
if (fileExists(fileName)) then
result := appendFile(fileName)
else
result := createFile(fileName);
except
writeln('OpenSRLLogFile: '+exceptionToString(exceptionType, exceptionParam));
end;
end;
procedure AddToReport(s: string);
var
tmpFile: integer;
begin
writeln(s);

tmpFile := OpenReportFile();

if (tmpFile >= 0) then
try
writeFileString(tmpFile,s);
// writeFileString(tmpFile, '['+msToTime(getTimeRunning(), TIME_BARE)+']: '+s+#13+#10);
except
Writeln('Error writing File');
finally
closeFile(tmpFile);
end;
end;
Begin
AddToReport('Hello')
End.