Results 1 to 14 of 14

Thread: Connected & WaitForConnection

  1. #1
    Join Date
    May 2007
    Location
    England
    Posts
    4,141
    Mentioned
    11 Post(s)
    Quoted
    266 Post(s)

    Default Connected & WaitForConnection

    Two functions which would come in handy for someone with a poor internet connection.

    What they do are check if you are connected to Runescape, via the Lost Connection box in the top left of your screen.

    Connected just returns true or false depending on whether you are connected or not.

    WaitForConnection again returns true if you are connected. If you are not connected though, it will wait MaxWaitMS to become connected. If it does not become connected after waiting, it returns false.

    Please do not hassle me about using a DTM; it is the first method which popped into my mind. Anyway, when I tested it, it only took
    Code:
    Successfully compiled (234 ms)
    to compile.

    SCAR Code:
    {*******************************************************************************
    function LostConnection : Boolean;
    By: R1ch
    Description: Checks if you are not connected to RS. Returns true if you are NOT connected.
    *******************************************************************************}

    function LostConnection : Boolean;
    var
      X, Y , Con : Integer;

    begin
      Con := DTMFromString('78DA63D4606060E061C00A1861B4079060439' +
           '5FBFFFF3FAA9A4820C145408D1390E025A0460D48F01150234F84' +
           '39224498C341841A90BF3908A81125C2EF2A408293801A7DC2E10' +
           'C0098072353');
      Result:= FindDTM(Con, X, Y , 0, 0, 250, 75)
      FreeDTM(Con);
    end;

    {*******************************************************************************
    function WaitForConnection(MaxWaitMS : Integer) : Boolean;
    By: R1ch
    Description: Checks if you are connected to RS. Returns true if you are.
                 If you are not, waits MaxWaitMS to become connected.
    *******************************************************************************}

    function WaitForConnection(MaxWaitMS : Integer) : Boolean;
    var
      I : Integer;
    begin
      I := GetSystemTime;
      while (GetSystemTime - I) < MaxWaitMS do
      begin
        Result:= not(LostConnection);
        if Result then
          Exit;
        Wait(Random(15));
      end;
    end;

    Comments?
    Last edited by Rich; 07-06-2009 at 04:51 AM.
    <3

    Quote Originally Posted by Eminem
    I don't care if you're black, white, straight, bisexual, gay, lesbian, short, tall, fat, skinny, rich or poor. If you're nice to me, I'll be nice to you. Simple as that.

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

    Default

    Would be more logical to have NotConnected since you are connected most of the time .

    But:
    SCAR Code:
    {*******************************************************************************
    function WaitForConnection(MaxWaitMS : Integer) : Boolean;
    By: R1ch
    Description: Checks if you are connected to RS. Returns true if you are.
                 If you are not, waits MaxWaitMS to become connected.
    *******************************************************************************}

    function WaitForConnection(MaxWaitMS : Integer) : Boolean;
    var
      I : Integer;
    begin
      i := GetSystemTime;
      while GetSystemTime - i < MaxWaitMS do
      begin
        result := Connected;
        if result then
          exit;
        Wait(Random(16));
      end;
    end;
    Last edited by Da 0wner; 07-05-2009 at 08:19 PM.

  3. #3
    Join Date
    May 2007
    Location
    England
    Posts
    4,141
    Mentioned
    11 Post(s)
    Quoted
    266 Post(s)

    Default

    I'll keep Connected, but I've also added NotConnected.

    EDIT: Shortened WaitForConnection.
    <3

    Quote Originally Posted by Eminem
    I don't care if you're black, white, straight, bisexual, gay, lesbian, short, tall, fat, skinny, rich or poor. If you're nice to me, I'll be nice to you. Simple as that.

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

    Default

    Check my edit.

    SCAR Code:
    unction NotConnected : Boolean;
    var
      X, Y , Con : Integer;

    begin
      Con := DTMFromString('78DA63D4606060E061C00A1861B4079060439' +
           '5FBFFFF3FAA9A4820C145408D1390E025A0460D48F01150234F84' +
           '39224498C341841A90BF3908A81125C2EF2A408293801A7DC2E10' +
           'C0098072353');
      Result:= FindDTM(Con, X, Y , 0, 0, 250, 75)
      FreeDTM(Con);
    end;
    ->
    SCAR Code:
    function NotConnected : boolean;
    begin
      result := not Connected;
    end;

  5. #5
    Join Date
    May 2007
    Location
    England
    Posts
    4,141
    Mentioned
    11 Post(s)
    Quoted
    266 Post(s)

    Default

    Meh, I don't see why I didn't do that to be honest.

    Thanks,
    Richard.
    <3

    Quote Originally Posted by Eminem
    I don't care if you're black, white, straight, bisexual, gay, lesbian, short, tall, fat, skinny, rich or poor. If you're nice to me, I'll be nice to you. Simple as that.

  6. #6
    Join Date
    Jan 2007
    Posts
    8,876
    Mentioned
    123 Post(s)
    Quoted
    327 Post(s)

    Default

    Why have both Connected and NotConnected? if you're not connected then Connected would result false...

  7. #7
    Join Date
    May 2007
    Location
    England
    Posts
    4,141
    Mentioned
    11 Post(s)
    Quoted
    266 Post(s)

    Default

    Quote Originally Posted by Zyt3x View Post
    Why have both Connected and NotConnected? if you're not connected then Connected would result false...
    That to me is like saying why have TypeSend as well as TypeSendEx. I get what you're saying, but in my opinion, it just makes things easier.
    <3

    Quote Originally Posted by Eminem
    I don't care if you're black, white, straight, bisexual, gay, lesbian, short, tall, fat, skinny, rich or poor. If you're nice to me, I'll be nice to you. Simple as that.

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

    Default

    Quote Originally Posted by R1ch View Post
    That to me is like saying why have TypeSend as well as TypeSendEx. I get what you're saying, but in my opinion, it just makes things easier.
    There's actually a logic behind TypeSendEx/TypeSend.

  9. #9
    Join Date
    May 2007
    Location
    England
    Posts
    4,141
    Mentioned
    11 Post(s)
    Quoted
    266 Post(s)

    Default

    Not trying to start an argument here, but instead of using TypeSend('bla'); you could use TypeSendEx('bla', True');. All TypeSend is is
    SCAR Code:
    procedure TypeSend(Text : string);
    begin
      TypeSendEx(Text, True);
    end
    It's the same concept with these.

    It's up to the Devs whether they get in or not anyway, so if they feel it doesn't need to be there, they don't add it.
    Last edited by Rich; 07-06-2009 at 02:14 AM.
    <3

    Quote Originally Posted by Eminem
    I don't care if you're black, white, straight, bisexual, gay, lesbian, short, tall, fat, skinny, rich or poor. If you're nice to me, I'll be nice to you. Simple as that.

  10. #10
    Join Date
    Jan 2007
    Posts
    8,876
    Mentioned
    123 Post(s)
    Quoted
    327 Post(s)

    Default

    Quote Originally Posted by R1ch View Post
    That to me is like saying why have TypeSend as well as TypeSendEx. I get what you're saying, but in my opinion, it just makes things easier.
    So therefore in your opinion we should have one LoggedIn and one NotLoggedIn?

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

    Default

    I think we should just have one...

  12. #12
    Join Date
    May 2007
    Location
    England
    Posts
    4,141
    Mentioned
    11 Post(s)
    Quoted
    266 Post(s)

    Default

    @ Zytex: What does it matter anyway? All I'm trying to do is help, and I get flamed for it. It's just stupid. It's up to the Devs, not you.

    @ Kyle: Which one?
    <3

    Quote Originally Posted by Eminem
    I don't care if you're black, white, straight, bisexual, gay, lesbian, short, tall, fat, skinny, rich or poor. If you're nice to me, I'll be nice to you. Simple as that.

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

    Default

    NotConnected .

  14. #14
    Join Date
    May 2007
    Location
    England
    Posts
    4,141
    Mentioned
    11 Post(s)
    Quoted
    266 Post(s)

    Default

    Fine. I give in. I've removed Connected, and renamed NotConnected to LostConnection.
    <3

    Quote Originally Posted by Eminem
    I don't care if you're black, white, straight, bisexual, gay, lesbian, short, tall, fat, skinny, rich or poor. If you're nice to me, I'll be nice to you. Simple as that.

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
  •