Page 1 of 2 12 LastLast
Results 1 to 25 of 40

Thread: [#29] SRL user-defined procedures!

  1. #1
    Join Date
    Jul 2007
    Location
    Norway.
    Posts
    1,938
    Mentioned
    3 Post(s)
    Quoted
    0 Post(s)

    [#29] SRL user-defined procedures!

    SRL user-defined procedures!



    With the release of revision #29, SRL now has a new feature available; user-definable procedures. Simply explained, they consist of an array of procedure variables which are called within various common SRL procedures and functions. It is nothing complicated at all, this is how the procedure variables are declared:

    SCAR Code:
    var
      srl_Procs: array [0..8] of procedure();

    The main purpose of these, as you'll find more about in this tutorial, is to assign your procedures of preferral, to these procedure variables. These assigned procedures will then be called whenever certain SRL functions which call these procedures, are called. For example, if a procedure is assigned to srl_Procs[SRL_AntiBan], that procedure will be called whenever Flag or FFlag is called. This might be useful for i.e. doing antiban actions while waiting for the flag to disappear of the minimap.

    Before you continue reading, you might want to take a look inside the globals.scar include (found in Includes/SRL/core folder). Once you open the include, scroll down to where you see all the SRL_On(...) constants. Here, you'll see which procedure variables that currently are available.

    SCAR Code:
    const
      srl_AntiBan = 0;      { Your AntiBan procedure to be called during various SRL functions and procedures. (Flag, FFlag) }
      srl_OnFindMod = 1;    { After a player or Jagex mod is detected talking in the chat box. }
      srl_OnFindDead = 2;   { After the text 'Oh dear you are dead' is detected. }
      srl_OnFindFight = 3;  { After detecting a fighting random. }
      srl_OnFindTrade = 4;  { After the trade has been attempted (either success or failure). }
      srl_OnNextPlayer = 5; { While the players are logged out and before CurrentPlayer changes. }
      srl_OnSendStats = 6;  { After SRL Script Stats are sent to the server. }
      srl_OnRandomCall = 7; { Called in FindNormalRandoms, FindInventoryRandoms, FindNonInventoryRandoms. (NOT ONLY WHEN RANDOMS ARE DETECTED). }
      srl_OnFindRandom = 8; { After a random event is detected. (FNR, FIR, FNIR, FT) }

    At the time of me writing this, the procedure array consists of 9 procedure variables. All of them have self-explanatory names and are clearly stating upon which situations they are called. In addition, the comments should help you understand every single one of them. But - remember that these constants only are integers which represent the position of the procedure that the constant represents, in the [0..8] array of procedures.

    Regarding that, let's take this constant as an example:

    SCAR Code:
    const
      srl_OnFindRandom = 8;

    That constant has an assigned value of 8, meaning that calling SRL_Procs[srl_OnFindRandom] would be the same as calling SRL_Procs[8] (Keep that in mind, we'll get right back to that.)

    Inside AntiRandoms.scar, where all the random detecting functions are, we currently have four procedures/functions that use the above mentioned constant. Whenever one of the procedures in that include (FindNormalRandoms, FindInventoryRandoms, FindNonInventoryRanoms, FindTalk) detects a random event in RuneScape, something like this gets executed:

    SCAR Code:
    if (srl_Procs[srl_OnFindRandom] <> nil) then
        srl_Procs[srl_OnFindRandom]();

    Two lines. So simple, yet so awesome. The first line, if (SRL_Procs[SRL_OnFindRandom] <> nil) then, checks whether the procedure SRL_Procs[SRL_OnFindRandom] variable is assigned to an actual procedure. Earlier above, our constant example "SRL_OnFindRandom" is declared as nothing more than an integer constant, yes? That makes the two lines above be the same as simply checking whether SRL_Procs[0] points to a procedure. So, basically - if a procedure has been assigned to SRL_Procs[SRL_OnFindRandom], this line returns true.

    And, the next line ofcourse calls the procedure assigned to the procedure variable, if it points to a procedure.

    Assigning a procedure to one of the procedure variables is really easy, it's almost like assigning normal variables! Just do like this:

    SCAR Code:
    srl_Procs[srl_OnFindRandom] := @AfterRandom;

    I told you it was easy!
    In the example line above, we assign srl_Procs[srl_OnFindRandom] to a procedure named AfterRandom; which should be declared in your script somewhere above where you actually assign it to a srl_Proc. Just don't remember to add a "@" before the procedure's name, as this is crucial for SCAR to interpret it correctly. Also, the procedure must NOT have any parameters!
    And that's all there is to it, now AfterRandom will be called every single time a random is found!

    Now with a full script example!

    SCAR Code:
    program SRLprocvarsexample;
    {.include SRL/SRL.scar}

    procedure LOL;
    begin
      WriteLn('Yay?');
    end;

    begin
      SetUpSRL;
      srl_Procs[0] := @LOL; { Here, we assign the SRL_Procs[0] variable (declared in Globals.scar) to procedure LOL;. }
      if (SRL_Procs[0] <> nil) then { Not really needed in this exact case, but just an example on
     how to check if a procedure variable actually is assigned to a procedure. }

        SRL_Procs[0](); { Here, we finally call the procedure assigned to the variable. }
    end.

    So, what is this system really good for?
    It has countless possibilities, the limit here is your mind.
    For example, why not do some quick antiban while waiting for the flag to dissapear? Switch gametabs, or something else less time consuming. And, what do you want to happen whenever you detect a RS moderator or if your player dies? While we're at it, why not switch worlds on NextPlayer or do something time consuming (like a GetPage) while the player is logged out?

    The possibilities are endless, use your imagination!

    This marks the end of this short tutorial. I hope you didn't mind reading it despite that it is in a slightly bad state. (Which I plan to improve on after I get some feedback.) Please give me and ideas or comments for what parts I explained wrongly or poorly, and any ideas, comments or tips are welcome!

    As a final notice, I highly recommend you to check out globals.scar to get better understanding of this feature. If there were any part that were hard to understand in this "tutorial", please let me know.


    Happy scripting ^^
    - EC!

  2. #2
    Join Date
    Jun 2008
    Location
    San Diego, California
    Posts
    276
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Ahh looks very cool, Its crazy how you devs come up with this stuff.
    Goodjob on this! Can't wait to use it!

    -The_Shermanator
    Current Project: All In 1 Falador Script - 20% DONE

  3. #3
    Join Date
    Feb 2006
    Location
    Amsterdam
    Posts
    13,691
    Mentioned
    146 Post(s)
    Quoted
    130 Post(s)

    Default

    Nice.



    The best way to contact me is by email, which you can find on my website: http://wizzup.org
    I also get email notifications of private messages, though.

    Simba (on Twitter | Group on Villavu | Website | Stable/Unstable releases
    Documentation | Source | Simba Bug Tracker on Github and Villavu )


    My (Blog | Website)

  4. #4
    Join Date
    Jul 2008
    Posts
    907
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    really nice :P, it's awesome


  5. #5
    Join Date
    Feb 2007
    Location
    Alberta,Canada
    Posts
    2,358
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    wow this is hawt. + rep.
    “Ignorance, the root and the stem of every evil.”

  6. #6
    Join Date
    Apr 2007
    Posts
    994
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    Mention that the procedure must be a procedure with no parameters?
    [QUOTE]<GoF`> oh no its Raymooond
    <Raymooond> Heya
    <GoF`> is it ray or some other ray?
    <LeeLokHin> No idea
    <LeeLokHin> Raymond, what's the game you like the most?
    <Raymooond> Runescape
    <-- LeeLokHin has kicked Raymooond from #srl (Faker.)[/QUOTE]

  7. #7
    Join Date
    Sep 2006
    Location
    include srl/srl.scar ( aussie)
    Posts
    2,875
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    This look's nice but i don't really undertand..

    Switch gametabs, or something else less time consuming. And, what do you want to happen whenever you detect a RS moderator or if your player dies? While we're at it, why not switch worlds on NextPlayer or do something time consuming (like a GetPage) while the player is logged out?

    But couldn't you just do..

    While FlagPresent do
    AntiBan;

    If FindMod then
    Switchworlds.

    etc, you can do all that stuff anyway?

  8. #8
    Join Date
    Jul 2007
    Location
    Norway.
    Posts
    1,938
    Mentioned
    3 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Wizzup? View Post
    Nice.
    Quote Originally Posted by The_Shermanator View Post
    Ahh looks very cool, Its crazy how you devs come up with this stuff.
    Goodjob on this! Can't wait to use it!

    -The_Shermanator
    Quote Originally Posted by sandos View Post
    really nice :P, it's awesome
    Quote Originally Posted by Blumblebee View Post
    wow this is hawt. + rep.
    Thanks to all of you!
    And, Blum, thanks for the rep+ ^^

    And, please do let me know if I missed something or made something unclear - or if you have any suggestions for anything I could add/improve.

    Quote Originally Posted by Lee Lok Hin View Post
    Mention that the procedure must be a procedure with no parameters?
    Whoops, forgot to add that. Thanks!

    Quote Originally Posted by NiCbaZ View Post
    This look's nice but i don't really undertand..




    But couldn't you just do..

    While FlagPresent do
    AntiBan;

    If FindMod then
    Switchworlds.

    etc, you can do all that stuff anyway?
    This system simply makes things easier, especially the "OnFindRandom" and such.

    And, your FlagPresent example, would you want that implemented in your script every single time you call (F)Flag? No. That's why you simply assign a procedure to it, and you only have to do it once.

  9. #9
    Join Date
    Sep 2006
    Location
    include srl/srl.scar ( aussie)
    Posts
    2,875
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Yes i undertand now, Thank you.

  10. #10
    Join Date
    Aug 2007
    Location
    Where do you live?
    Posts
    934
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Awesome, jus read bout these in the thread bout rev 29 and 30 Good job, not much more you can put in tut, peeps jus gotta play wit it for them selves I'll have fun wit these

    Thanks

  11. #11
    Join Date
    Mar 2007
    Location
    <3
    Posts
    2,683
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Call it gravedig, but i had to Thank you for this tut.
    Really nice work Ec!.

  12. #12
    Join Date
    May 2006
    Location
    Amsterdam
    Posts
    3,620
    Mentioned
    5 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by N1ke! View Post
    Call it gravedig, but i had to Thank you for this tut.
    Really nice work Ec!.
    afaik, you cannot gravedig tutorials.
    Verrekte Koekwous

  13. #13
    Join Date
    Feb 2006
    Location
    Amsterdam
    Posts
    13,691
    Mentioned
    146 Post(s)
    Quoted
    130 Post(s)

    Default

    Quote Originally Posted by N1ke! View Post
    Call it gravedig, but i had to Thank you for this tut.
    Really nice work Ec!.
    I think this is SRL's latest feature, how is it a gravedig?



    The best way to contact me is by email, which you can find on my website: http://wizzup.org
    I also get email notifications of private messages, though.

    Simba (on Twitter | Group on Villavu | Website | Stable/Unstable releases
    Documentation | Source | Simba Bug Tracker on Github and Villavu )


    My (Blog | Website)

  14. #14
    Join Date
    Jul 2007
    Location
    Right now? Chair.
    Posts
    8,488
    Mentioned
    3 Post(s)
    Quoted
    12 Post(s)

    Default

    testing something

    ~RM

    I & I know Zion. It is in the spirit, body and mind of every one of us
    RMouse(obj: TMSIObject): boolean;

  15. #15
    Join Date
    Jan 2008
    Location
    California, US
    Posts
    2,765
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Can you please add ThreadSafeCall to this? So we can have parameters.

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

    Default

    Quote Originally Posted by Da 0wner View Post
    Can you please add ThreadSafeCall to this? So we can have parameters.
    Parameters would be a nightmare IMO. How would it know what parameters to pass? I guess you could have a whole other array of TVaraintArrays to pass, but that would be messy. You'd have to edit an array, maybe multiple times just to pass a couple parameters. If you really want to pass parameters, you could just create a no-parameter procedure and have it call the main one with parameters. The other downside to it is, AFAIK, parameters passed via ThreadSafeCall cannot be passed by reference (or at least edited).

    Of course you may have a reason/solution I didn't think of?

  17. #17
    Join Date
    Jan 2008
    Location
    California, US
    Posts
    2,765
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    SCAR Code:
    program New;

    type
      TProc = record
        Name : string;
        Params : TVariantArray;
      end;

    var
     srl_Procs: array [0..8] of TProc;

    function TestProc1(s : string; i : integer) : string;
    begin
      result := 'TheResult';
      Writeln(s);
      Writeln(IntToStr(i));
    end;

    function CallProc(Index : integer) : string;
    begin
      try
        result := ThreadSafeCall(srl_Procs[Index].Name, srl_Procs[Index].Params);
      except end;
    end;

    procedure SetParams(Index : integer; Params : TVariantArray);
    begin
      srl_Procs[Index].Params := Params;
    end;

    begin
      srl_Procs[0].Name := 'TestProc1';
      SetParams(0, ['hello', 1337]);
      Writeln(callProc(0));
    end.

    .
    Last edited by Da 0wner; 07-12-2009 at 08:50 AM.

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

    Default

    Quote Originally Posted by Da 0wner View Post
    SCAR Code:
    program New;

    type
      TProc = record
        Name : string;
        Params : TVariantArray;
      end;

    var
     srl_Procs: array [0..8] of TProc;

    function TestProc1(s : string; i : integer) : string;
    begin
      result := 'TheResult';
      Writeln(s);
      Writeln(IntToStr(i));
    end;

    function CallProc(Index : integer) : string;
    begin
      try
        result := ThreadSafeCall(srl_Procs[Index].Name, srl_Procs[Index].Params);
      except end;
    end;

    procedure SetParams(Index : integer; Params : TVariantArray);
    begin
      srl_Procs[Index].Params := Params;
    end;

    begin
      srl_Procs[0].Name := 'TestProc1';
      SetParams(0, ['hello', 1337]);
      Writeln(callProc(0));
    end.

    .
    Interesting, very interesting....

  19. #19
    Join Date
    Jan 2008
    Location
    California, US
    Posts
    2,765
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Seems more powerful than the current system .

  20. #20
    Join Date
    May 2006
    Location
    Amsterdam
    Posts
    3,620
    Mentioned
    5 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Da 0wner View Post
    Seems more powerful than the current system .
    But it's quite useless, afaik? Name an event where you need parameters to be added..
    Verrekte Koekwous

  21. #21
    Join Date
    Jan 2008
    Location
    California, US
    Posts
    2,765
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Maybe getting what random is currently active or something.

    You can be imaginative. I'm not really sure, but I don't see why it shouldn't be added. It adds more flexibility.

  22. #22
    Join Date
    Feb 2006
    Location
    Belgium
    Posts
    3,137
    Mentioned
    3 Post(s)
    Quoted
    5 Post(s)

    Default

    Using ThreadSafeCall to do this is a really bad idea because it synchronizes the script thread with the main thread... And the functions in SCAR are written to run in a separated thread, so synchronizing some of them would not be wise, however, I can probably add a CallProc function to SCAR instead which doesn't synchronize threads, of course it can't be used for forms then simply because it wouldn't be thread-safe then. For forms you'd still need ThreadSafeCall.

  23. #23
    Join Date
    Jan 2008
    Location
    California, US
    Posts
    2,765
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Sure, CallProc would be nice in 3.22 or 3.21a or whatever .

    Hold my suggestion for this until Freddy releases a new SCAR with CallProc.

  24. #24
    Join Date
    Feb 2006
    Location
    Belgium
    Posts
    3,137
    Mentioned
    3 Post(s)
    Quoted
    5 Post(s)

    Default

    Quote Originally Posted by Da 0wner View Post
    Sure, CallProc would be nice in 3.22 or 3.21a or whatever .

    Hold my suggestion for this until Freddy releases a new SCAR with CallProc.
    I've added CallProc to SCAR, it's available from #7 in the SCAR Pre-release SVN.

  25. #25
    Join Date
    Jan 2008
    Location
    California, US
    Posts
    2,765
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Oh, thanks <3 .

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. User Defined Types in Scar?
    By Jackrawl in forum OSR Help
    Replies: 8
    Last Post: 05-04-2008, 07:39 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
  •