Results 1 to 11 of 11

Thread: WriteLn intercept?

  1. #1
    Join Date
    Feb 2009
    Location
    Nebraska
    Posts
    68
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default WriteLn intercept?

    Is there a way for a script to hook WriteLn such that the text can be modified before being written out?

    It looks like I could go back and maybe delete and rewrite lines that were written so they conform to the format I want, but I don't see a way to catch and modify them beforehand.

  2. #2
    Join Date
    Jul 2008
    Location
    Canada
    Posts
    1,612
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Not hard at all, that's if i grasp what you are asking.

    Example:
    SCAR Code:
    program New;

    const
      Words = 'Hello World!'; //Words can be anything really..like ...Writein would even work~

    begin
      Writeln(Words);
    end.

    Pretty Simple

    There are also other ways, like if words would be a variable etc.

  3. #3
    Join Date
    May 2008
    Location
    Here :p
    Posts
    194
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    ok i think u mean 1 of 2 things...
    1.
    you whant to chage a line you have already writen in with case just use ReplaceDebugLine(Line: Integer; s: string); to find the last line you wrote you can use GetDebugLineCount; or just use clearDebug (will delete everything) and use writeln again which will make it look like you have edited it.

    2. you can just edit the actual line while your calling writeln for exsample if you whant to format the date writeln(IntToStr(Days) + IntToStr(months) + IntToStr(years));
    just add things with +'s and strings eg.
    writeln(IntToStr(Days) + ' - ' + IntToStr(months) + ' - ' + IntToStr(years));

    hope taht helps but it would be simpiler if you told us what exsaculy it is you whant to do.

    EDIT: if you whant to change the absolute basic of what is written so insted of it just writing the string it will always write say 'DEBUG: ' before hand you will need to write a plugin and edit writeln but taht requires Delphi + alot of scripting knowlage but i belive the test plugin does somthing like that.

  4. #4
    Join Date
    Feb 2009
    Location
    Nebraska
    Posts
    68
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by BazzBarrett View Post
    ok i think u mean 1 of 2 things...
    EDIT: if you whant to change the absolute basic of what is written so insted of it just writing the string it will always write say 'DEBUG: ' before hand you will need to write a plugin and edit writeln but taht requires Delphi + alot of scripting knowlage but i belive the test plugin does somthing like that.
    This is what I'm after. Various code within includes I might have use WriteLn to output various strings. I want to do something like sticking 'DEBUG: ' in front of each string that will appear in the output no matter where in the scripts WriteLn is called from.

    I'm willing to add a plugin to do this, sounds fairly easy, so I'll explore some more.

  5. #5
    Join Date
    Oct 2006
    Location
    ithurtsithurtsithurtsithurts
    Posts
    2,930
    Mentioned
    7 Post(s)
    Quoted
    135 Post(s)

    Default

    Just write another procedure to do that, and use it instead of writeln. Here, try this:
    SCAR Code:
    procedure WriteLnD(s : String);
    begin
    Writeln('Debug: ' + s);
    end;

    Then when you would use writeln, use writelnd instead.

  6. #6
    Join Date
    Jun 2006
    Posts
    3,861
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    SCAR Code:
    procedure WriteLn(s: String);
    begin
      ReplaceDebugLine(GetDebugLineCount, 'DEBUG: ' + s);
    end;

    begin
      writeln('rawr');
    end.

  7. #7
    Join Date
    Feb 2009
    Location
    Nebraska
    Posts
    68
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by senrath View Post
    Just write another procedure to do that, and use it instead of writeln.
    The problem with this is that routines in includes that still use WriteLn will appear in the output unmodified.

  8. #8
    Join Date
    Feb 2009
    Location
    Nebraska
    Posts
    68
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Grippy View Post
    I'm willing to add a plugin to do this, sounds fairly easy, so I'll explore some more.
    Ok, after a brief look around it appears I'll need to retrieve the pointer to SCAR's WriteLn function, patch in my version to replace it and finally call back down to SCAR's original WriteLn.

    Sounds reasonable. Does SCAR take any steps to prevent patching of this sort, or is that an acceptable hack?

  9. #9
    Join Date
    Jun 2006
    Posts
    3,861
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    Quote Originally Posted by Grippy View Post
    Ok, after a brief look around it appears I'll need to retrieve the pointer to SCAR's WriteLn function, patch in my version to replace it and finally call back down to SCAR's original WriteLn.

    Sounds reasonable. Does SCAR take any steps to prevent patching of this sort, or is that an acceptable hack?
    My method works fine if you save it to a file and include it first (I don't know why it has to be included, and can't just be in the main script..)

    But if you want to have a plugin, here's the source: http://pastebin.com/m3a53c2d

  10. #10
    Join Date
    Feb 2009
    Location
    Nebraska
    Posts
    68
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by bullzeye95 View Post
    My method works fine if you save it to a file and include it first (I don't know why it has to be included, and can't just be in the main script..)
    No, you're right, it's working for me just fine in the main script, long as it's above the includes.

    Does this work for you too?:

    Code:
    program HelloRS;
    
    procedure writeln( s: string);
    begin
      ReplaceDebugLine(GetDebugLineCount, 'DEBUG: ' + s);
    end;
    
    {.include SRL\SRL.scar}
    
    begin
      ClearDebug;
      WriteLn( 'test1' );
      SetupSRL;  // note, 'SRL Compiled...' message is prefixed.
      WriteLn( 'test2' );
    end.
    Code:
    DEBUG: test1
    DEBUG: SRL Compiled in 10 msec
    DEBUG: test2
    Successfully executed
    Perfect, thanks!

  11. #11
    Join Date
    Jun 2006
    Posts
    3,861
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    Ah, I forgot it compiles from the top down, regardless of include positions..

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Writeln
    By seany in forum OSR Help
    Replies: 5
    Last Post: 10-11-2008, 01:49 PM
  2. Writeln help
    By rogeruk in forum OSR Help
    Replies: 9
    Last Post: 08-23-2007, 09:21 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
  •