Results 1 to 14 of 14

Thread: ClickOption - My suggestion for Text.scar

  1. #1
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default ClickOptionEx/ClickOption - My suggestions for Text.scar

    I posted this a while back, and it slowly died, so I have improved it slightly, and I'm coming back for round two, hoping to get some more feedback. I have noticed that throughout scripts people like to write some code that randomly right/left clicks when clicking an object.

    Therefore, I have come up with this function that does just that, but it also checks the uptext of the object, and chooses the correct option.

    Because a human isn't going to right/left click 50% percent of the time, this function is set to right click and choose option once every 10 times it is called.
    SCAR Code:
    {*******************************************************************************
    function ClickOptionEx(x, y, rx, ry: Integer; Option: String; UpText, ChooseOpt: TStringArray): Boolean;
    By: Coh3n
    Description: Will left click an object 9/10 times.  Will right click an object
                 and choose the option accociated with ChooseOpt.
                 Valid arguments for Option: 'right', 'left', 'random'.
                 i.e ClickOption(x, y, 0, 0, 'random', ['Door'], ['Open']);
    *******************************************************************************}


    function ClickOptionEx(x, y, rx, ry: Integer; Option: String; UpText, ChooseOpt: TStringArray): Boolean;
    begin
      if not InStrArr(Option, ['random', 'right', 'left'], False) then Exit;
      Result := WaitUpTextMulti(UpText, 100 + Random(400));
      if not Result then SRL_Warn;
      if Option = 'random' then
        if Random(10) = 1 then
          Option := 'right';
        else
          Option := 'left';
      Mouse(x, y, rx, ry, Option = 'left');
      if Option = 'right' then
        ChooseOptionMulti(ChooseOpt);
    end;

    {*******************************************************************************
    function ClickOption(x, y, rx, ry: Integer; Option: String; UpText, ChooseOpt: String): Boolean;
    By: Coh3n
    Description: Works like ClickOptionEx, but uses Strings instead of TStingArray.
    *******************************************************************************}


    function ClickOption(x, y, rx, ry: Integer; Option: String; UpText, ChooseOpt: String): Boolean;
    begin
      Result := ClickOptionEx(x, y, rx, ry, Option, [UpText], [ChooseOpt]);
    end;
    *Thanks to Sabzi for the ClickOption idea.

    I have used it in my current script project to open a gate and climb-over a stile, and both work like a charm. I find this function handy to replace a bunch of lines of code such as:
    SCAR Code:
    MMouse(x, y, 4, 4);
    if IsUpText('illow') then
    begin
      Writeln('We have found the Willow tree');
      case Random(10) of
        1: begin
             Mouse(x, y, 0, 0, False);
             Wait(80 + Random(100));
             ChooseOption('hop');
           end;
      else
        Mouse(x, y, 0, 0, True);
    end;
    With this much shorter code:
    SCAR Code:
    MMouse(x, y, 4, 4);
    if ClickOption(x, y, 0, 0, 'random', 'illow', 'hop') then
      Writeln('Clicked Willow tree!');
    See what I mean?

    Well, that's it, thanks for reading. Please post comments/suggestions.
    Last edited by Coh3n; 08-16-2009 at 09:48 PM.

  2. #2
    Join Date
    Nov 2008
    Location
    Norway, Alesund
    Posts
    924
    Mentioned
    0 Post(s)
    Quoted
    37 Post(s)

    Default

    nice!
    but i dont like

    Code:
    if ClickOption(x, y, 0, 0, 'random', ['illow'], ['hop']) then
    this [] why 'random' don't have these? i think 'illow' and 'hop' shouldn't have it. just for easier writing. function is nice really. rep+

    EDIT: 1st Post.

  3. #3
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    Quote Originally Posted by Laimonas171 View Post
    nice!
    but i dont like


    if ClickOption(x, y, 0, 0, 'random', ['illow'], ['hop']) then
    this [] why 'random' don't have these? i think 'illow' and 'hop' shouldn't have it. just for easier writing. function is nice really. rep+
    Thanks! And the reason they have the square brackets is because they are both TStringArrays and can be written like ['Willow', 'illow', 'low']. See what I mean? I can make it simpler if need be, but this way there are more options. Also, 'random' doesn't have square brackets because it is just a normal string, not a TStringArray.

    Thanks a lot for the quick feedback.

  4. #4
    Join Date
    Nov 2008
    Location
    Norway, Alesund
    Posts
    924
    Mentioned
    0 Post(s)
    Quoted
    37 Post(s)

    Default

    Quote Originally Posted by Coh3n View Post
    Thanks! And the reason they have the square brackets is because they are both TStringArrays and can be written like ['Willow', 'illow', 'low']. See what I mean? I can make it simpler if need be, but this way there are more options. Also, 'random' doesn't have square brackets because it is just a normal string, not a TStringArray.

    Thanks a lot for the quick feedback.
    Oh ['Willow', 'illow', 'low'] this kind i like much more (Y)

  5. #5
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    Quote Originally Posted by Laimonas171 View Post
    Oh ['Willow', 'illow', 'low'] this kind i like much more (Y)
    Well in the function I use WaitUpTextMulti(); I could just as easy use WaitUpText(); and then you would declare it as 'illow'. However, it is more accurate to use a TStringArray.

  6. #6
    Join Date
    Feb 2009
    Location
    Hungary (GMT + 1)
    Posts
    1,774
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    As far as I can see in SRL, functions like this are the "Ex" versions.
    So your function would be the "Ex" version (ClickOptionEx) and what Laimonas171 wanted first would be the simple version.
    It would use the Ex version like:
    SCAR Code:
    function ClickOption(x, y, rx, ry: Integer; Option, UpText, ChooseOpt: String): Boolean;

    begin
      Result := ClickOptionEx(x, y, rx, ry, Option, [UpText], [ChooseOpt]);
    end;

    I am not sure though.

    By the way I really like the idea and the function itself.

  7. #7
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    Quote Originally Posted by Sabzi View Post
    As far as I can see in SRL, functions like this are the "Ex" versions.
    So your function would be the "Ex" version (ClickOptionEx) and what Laimonas171 wanted first would be the simple version.
    It would use the Ex version like:
    SCAR Code:
    function ClickOption(x, y, rx, ry: Integer; Option, UpText, ChooseOpt: String): Boolean;

    begin
      Result := ClickOptionEx(x, y, rx, ry, Option, [UpText], [ChooseOpt]);
    end;

    I am not sure though.

    By the way I really like the idea and the function itself.
    Hmm thanks very much, and I think you're right about the "Ex" thing. If this actually gets considered for SRL I think I will do that. Or you can, and I'll add it to the first post (crediting you of course).

  8. #8
    Join Date
    Feb 2009
    Location
    Hungary (GMT + 1)
    Posts
    1,774
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Credit yourself Coh3n, the function is written. Your is the "Ex". Just rename it if you want and the "simple" would be what I have posted above. There's nothing to really do anything with it, I was just wondering about that

  9. #9
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    Quote Originally Posted by Sabzi View Post
    Credit yourself Coh3n, the function is written. Your is the "Ex". Just rename it if you want and the "simple" would be what I have posted above. It's nothing to really do with anything I was just wondering about that
    Haha well alright, but yeah I'm pretty sure you are correct.

    EDIT: Added to the first post.

  10. #10
    Join Date
    Aug 2009
    Location
    Nova Scotia, Canada
    Posts
    604
    Mentioned
    0 Post(s)
    Quoted
    56 Post(s)

    Default

    [QUOTE=Coh3n;616318]I have noticed that throughout scripts people like to write some code that randomly right/left clicks when clicking an object./QUOTE]

    Talk about timing! I just finished writing code to do just that in my script, but yours is so much nicer! Gonna use this in my script (with full credit of course).

  11. #11
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    [QUOTE=Bixby Sayz;622051]
    Quote Originally Posted by Coh3n View Post
    I have noticed that throughout scripts people like to write some code that randomly right/left clicks when clicking an object./QUOTE]

    Talk about timing! I just finished writing code to do just that in my script, but yours is so much nicer! Gonna use this in my script (with full credit of course).
    Hey that's great! I'm glad to see that someone other than me is going to use it.

    Thanks!

  12. #12
    Join Date
    Oct 2007
    Location
    #srl
    Posts
    6,102
    Mentioned
    39 Post(s)
    Quoted
    62 Post(s)

    Default

    Honestly,
    SCAR Code:
    MMouse(x, y, 4, 4);
    if IsUpText('illow') then
    begin
      Writeln('We have found the Willow tree');
      case Random(10) of
        1: begin
             Mouse(x, y, 0, 0, False);
             Wait(80 + Random(100));
             ChooseOption('hop');
           end;
      else
        Mouse(x, y, 0, 0, True);
    end;
    Could just be:
    SCAR Code:
    MMouse(x, y, 4, 4);
    if IsUpText('illow') then
    begin
      Writeln('We have found the Willow tree');
      Bool := Random(10) = 1;
      Mouse(x, y, 0, 0, Bool);
      WaitOption('hop', 3000);
    end;

    It's not a bad idea though

  13. #13
    Join Date
    Feb 2009
    Location
    Hungary (GMT + 1)
    Posts
    1,774
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by NCDS View Post
    Honestly,
    SCAR Code:
    MMouse(x, y, 4, 4);
    if IsUpText('illow') then
    begin
      Writeln('We have found the Willow tree');
      case Random(10) of
        1: begin
             Mouse(x, y, 0, 0, False);
             Wait(80 + Random(100));
             ChooseOption('hop');
           end;
      else
        Mouse(x, y, 0, 0, True);
    end;
    Could just be:
    SCAR Code:
    MMouse(x, y, 4, 4);
    if IsUpText('illow') then
    begin
      Writeln('We have found the Willow tree');
      Bool := Random(10) = 1;
      Mouse(x, y, 0, 0, Bool);
      WaitOption('hop', 3000);
    end;

    It's not a bad idea though
    RBoolEx(10)

    SCAR Code:
    MMouse(x, y, 4, 4);
    if IsUpText('illow') then
    begin
      Writeln('We have found the Willow tree');
      Mouse(x, y, 0, 0, RBoolEx(10));
      WaitOption('hop', 3000);
    end;
    Any more licit?

  14. #14
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    Quote Originally Posted by NCDS View Post
    It's not a bad idea though
    Haha thanks, and wow I never realized you could make it into only a couple lines.

Thread Information

Users Browsing this Thread

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

Posting Permissions

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