Results 1 to 12 of 12

Thread: Quick Tut on Debug Box manipulation

  1. #1
    Join Date
    Dec 2006
    Location
    Copy pastin to my C#
    Posts
    3,788
    Mentioned
    8 Post(s)
    Quoted
    29 Post(s)

    Default Quick Tut on Debug Box manipulation

    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 -

    SCAR Code:
    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.


    Code:
    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


    Code:
    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


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



    Code:
    procedure ClearDebug;
    Clears debug box.
    Clears the whole debug box.


    Code:
    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...

  2. #2
    Join Date
    Feb 2006
    Location
    Helsinki, Finland
    Posts
    1,395
    Mentioned
    30 Post(s)
    Quoted
    107 Post(s)

    Default

    Nice job n3ss3s!

    DeleteDebugLine and ClearDebugLine aren't the same, though.

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

    Test and see the results:

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

  3. #3
    Join Date
    Dec 2006
    Location
    Copy pastin to my C#
    Posts
    3,788
    Mentioned
    8 Post(s)
    Quoted
    29 Post(s)

    Default

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

  4. #4
    Join Date
    Apr 2007
    Location
    Perth, Australia
    Posts
    3,926
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

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

  5. #5
    Join Date
    Dec 2006
    Location
    Copy pastin to my C#
    Posts
    3,788
    Mentioned
    8 Post(s)
    Quoted
    29 Post(s)

    Default

    You can if you want to

  6. #6
    Join Date
    Aug 2007
    Location
    Emo-land
    Posts
    1,109
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    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...
    SCAR Code:
    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

  7. #7
    Join Date
    Apr 2007
    Location
    Perth, Australia
    Posts
    3,926
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    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.

    SCAR Code:
    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).

    SCAR Code:
    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:

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

    The important part is this line:
    SCAR Code:
    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.

  8. #8
    Join Date
    Apr 2007
    Posts
    2,593
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

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

  9. #9
    Join Date
    Apr 2007
    Location
    Perth, Australia
    Posts
    3,926
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    Quote Originally Posted by TheVoiceInYourHead View Post
    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.

  10. #10
    Join Date
    Apr 2007
    Posts
    2,593
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    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.

  11. #11
    Join Date
    Apr 2007
    Location
    Perth, Australia
    Posts
    3,926
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    Quote Originally Posted by TheVoiceInYourHead View Post
    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:

    SCAR Code:
    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.

  12. #12
    Join Date
    Jul 2008
    Posts
    31
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Abstract Photo Manipulation
    By Torrent of Flame in forum Graphics and Multimedia
    Replies: 17
    Last Post: 03-02-2009, 07:13 PM
  2. functions w/ bit manipulation
    By sherlockmeister in forum Research & Development Lounge
    Replies: 9
    Last Post: 04-06-2008, 06:19 PM
  3. whole 55 lines to debug
    By HarryJames in forum OSR Help
    Replies: 3
    Last Post: 03-19-2007, 08:35 PM
  4. string variable manipulation?
    By bobert5696 in forum OSR Help
    Replies: 15
    Last Post: 02-24-2007, 06:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •