SRL Archive - OSR Advanced Scripting Tutorials

Quick Tut on Debug Box manipulation


n3ss3s

2008-01-24 09:23:26

procedure ClearDebug;
Clears debug box.

procedure DeleteDebugLine(Line: Integer);
Deletes a line from the debug box.

function GetDebugLineCount: Integer;
Get the number of lines in the debug box.

function GetDebugText: string;
Gets the text in the debugbox.

function GetDebugLine(Line: Integer): string;
Returns a certain given line of the debug box.

procedure ClearDebugLine(Line: Integer);
Clears a certain line of the debug box.

procedure ReplaceDebugLine(Line: Integer; s: string);
Replaces a certain line of the debug box.



We don't have a preserved array of string of the debug box line, but, we do have the line numbers ;)

GetDebugLineCount is your friend.

Finding a string in debug box and returning its line -


Function GetLineOf(S: String): Integer;
Var
C: Integer;
Begin
C := GetDebugLineCount;
For Result := 0 To C Do
If Pos(S, GetDebugLine(Result)) <> 0 Then
Exit;
End;

And you also see how to use a for loop without having to type Var and all the other stuff :)

The Result variable goes through all the debug lines, and when it's found the one you want, it exits the procedure. Voila.


function GetDebugText: string;
Gets the text in the debugbox.

It gets the WHOLE text of the debug box, it might not be something you really want to use.

BUT, it has this useful priority that it puts some space between the lines in the result, so, you can quickly split the whole debug box to a string array :)


procedure DeleteDebugLine(Line: Integer);
Deletes a line from the debug box.

To be used with something like the GetLineOf that I made above, for example if you don't like the way that AutoColor functions spit out the result - "RockColor =.." you can just use these to delete them all from your debug box :)


procedure ReplaceDebugLine(Line: Integer; s: string);
Replaces a certain line of the debug box.

Replaces a certain line of the debug box. :p



procedure ClearDebug;
Clears debug box.

Clears the whole debug box.


procedure ClearDebugLine(Line: Integer);
Clears a certain line of the debug box.

Freddy had obviously worked himself too tired, the same as deleting a line.


Very small tut, but hope it helped you…

Janilabo

2008-01-24 09:58:23

Nice job n3ss3s! :)

DeleteDebugLine and ClearDebugLine aren't the same, though. :p

ClearDebugLine just clears the line, but DeleteDebugLine actually deletes that line from debug box..

Test and see the results:

DeleteDebugLine
begin
ClearDebug;
WriteLn('Test 1');
WriteLn('Test 2');
WriteLn('Test 3');
DeleteDebugLine(1);
end.

ClearDebugLine
begin
ClearDebug;
WriteLn('Test 1');
WriteLn('Test 2');
WriteLn('Test 3');
ClearDebugLine(1);
end.

n3ss3s

2008-01-24 10:24:36

x) Thanks, Freddy supports Debug Line Recycling (DLR?) :)

ZephyrsFury

2008-01-24 20:36:43

n3ss3s I've got a couple of examples of this in a script. Would you like me to post them?

n3ss3s

2008-01-25 07:22:31

You can if you want to :)

FrÕzÑ_§ÕµL

2008-01-26 01:34:57

Heres what I use, it's used after logging in cause I don't like it how LoginPlayer writes the players name in the debug box the way the player wrote it so…
 for i := 0 to 3 do
if Trim(GetDebugLine(GetDebugLineCount - i)) = Players[CurrentPlayer].Name then
Begin
ReplaceDebugLine(GetDebugLineCount - i, Capitalize(Players[CurrentPlayer].Name) + ': Lets Cut Some ' + Tree + 's!');
Break;
end;

i.e. what it does is replaces :

fr0zn s0ul
Creating the NickTPA.

with

Fr0zn S0ul: Lets Cut Some Yews!
Creating the NickTPA.

Probably don't need the Trim, and you could use n3ss3s's idea of pos but hey, it's only debug box (yes its a random tutorial I admit) and no one particularly cares if its a bit longer than needed :)

ZephyrsFury

2008-01-26 04:44:32

Ok heres a little addon that n3ss3s has allowed me to add

Ex.1 Copying the proggie into a textfile
This is useful for scripters who want to prevent script users from accidently forgetting to save the proggie.


procedure SaveDebugToFile;
var
DebugText: string; DebugFile: Integer;
begin
DebugFile := RewriteFile(ScriptPath + 'Zephyr''s Rune Mysteries Quest Runner Progress Report' + '.txt', False);
DebugText := GetDebugText;
WriteFileString(DebugFile, DebugText);
WriteLn('Saved debug to file: ' + ScriptPath + 'Zephyr''s Rune Mysteries Quest Runner Progress Report' + '.txt');
CloseFile(DebugFile);
end;

As you can see, the debug is stored in the DebugText variable which is then written to the file using WriteFileString.

Ex.2 A countdown
Well the usefulness of this is questionable but I use it my shutdown function to make it look cool (if that is the right word).


procedure Shutdown;
var
Timer, Temp2, Temp1: string;
Spaces: Integer;
begin
WriteLn('[------------------------------------------------------------------------------]');
WriteLn('[ ]');
WriteLn('[ ]');
WriteLn('[ ]');
WriteLn('[------------------------------------------------------------------------------]');

for i := 30 downto 0 do
begin
if (i = 0) then
Timer := 'Shutting down...'
else
Timer := '[Shutting down in ' + IntToStr(i) + ' seconds... Press Ctrl-Alt-S to stop.]';
Spaces := 78 - Length(Timer);
Temp1 := Timer;
for j := 0 to Ceil(Spaces / 2) do
Insert(' ', Temp1, 2);
Temp2 := Temp1;
for j := 0 to Floor(Spaces / 2) do
Insert(' ', Temp2, Length(Temp1));
ReplaceDebugLine(GetDebugLineCount - 3, Temp2);
Wait(1000);
end;

Thats the first part of it where it writes stuff in the debug box. Most of it is just so it looks nice but just ignore that. You just have to know that it looks something like this:


[------------------------------------------------------------------------------]
[ ]
[ Shutting down in 30 seconds... Press Ctrl-Alt-S to stop. ]
[ ]
[------------------------------------------------------------------------------]

The important part is this line:

ReplaceDebugLine(GetDebugLineCount - 3, Temp2);

It uses GetDebugLineCount to get the last line of the debug then takes 3 to get the third last line of the debug. It then replaces this line with a new line. This effectively counts down from 30 all the wait to 0. Of course you could also go ClearDebug but this clears the whole debug which I do not want.

TViYH

2008-05-21 19:59:20

Is there any way of finding just a piece of text in the debugbox and returning it's line number?

ZephyrsFury

2008-05-22 05:33:45

From: TheVoiceInYourHead
Is there any way of finding just a piece of text in the debugbox and returning it's line number?


n3ss3s has a little function in the first post: GetLineOf.

TViYH

2008-05-22 15:05:47

But you have to use the entire line to find it. I need something that would find a "dynamic" debug line. It only has 2 words the same each time.

ZephyrsFury

2008-05-23 04:18:37

From: TheVoiceInYourHead
But you have to use the entire line to find it. I need something that would find a "dynamic" debug line. It only has 2 words the same each time.


n3ss3s function uses Pos so you only need to enter a part of the line. You could also edit it so it checks for an array of strings:


Function GetLineOfEx(SA: TStringArray): Integer;
Var
C, i: Integer;
Begin
C := GetDebugLineCount;
For Result := 0 To C Do
for i := 0 to High(SA) do
If Pos(SA[i], GetDebugLine(Result)) <> 0 Then
Exit;
End;

Should work.

sink998

2008-09-15 21:31:04

is there a way for scar to get the text and paste it on the area would help peaple when using forms then you wouldnt need to type it out.