Results 1 to 15 of 15

Thread: Getting Myself Confused...

  1. #1
    Join Date
    Dec 2010
    Posts
    808
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Getting Myself Confused...

    Ok so I want to make a kind of "location" function...
    Simba Code:
    Function WhatUp(T : String);
    Begin
           Case T Of
           'Banked' : WalkToTrees;
           'At Trees' : ChopTrees;
           'Chopped Trees' : WalkToBank;
           'At Bank' : DoBank;
           End;
    End;

    So from there can I just call:
    Simba Code:
    WhatUp('Banked');

    I kind of improvised as I wrote this thread so sorry if its bad :P

    Thankyoooo
    -Boom

  2. #2
    Join Date
    Feb 2009
    Location
    Irvine, CA
    Posts
    2,873
    Mentioned
    8 Post(s)
    Quoted
    138 Post(s)

    Default

    no, what i would do is something like this:

    Simba Code:
    {$i SRL\SRL.scar}


    function WalkToTrees: Boolean;
    begin
    end;

    function ChopTrees: Boolean;
    begin
    end;

    function WalkToBank: Boolean;
    begin
    end;

    function DoBank: Boolean;
    begin
    end;


    begin
      Case Lowercase(Players[CurrentPlayer].Loc) of
        'banked':
        if WalkToTrees then
          Players[CurrentPlayer].Loc := 'at trees';
        'at trees':
        if ChopTrees then
          Players[CurrentPlayer].Loc := 'chopped trees';
        'chopped trees':
        if WalkToBank then
          Players[CurrentPlayer].Loc := 'at bank';
        'at bank':
        if DoBank then
          Players[CurrentPlayer].Loc := 'banked';
      end;
    end.

    questions?

  3. #3
    Join Date
    Dec 2010
    Posts
    808
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    So it would be:
    Simba Code:
    {$i SRL\SRL.scar}


    function WalkToTrees: Boolean;
    begin
    //Walking stuff here
    Players[CurrentPlayer].Loc := 'At Trees';
    end;

    function ChopTrees: Boolean;
    begin
    end;

    function WalkToBank: Boolean;
    begin
    end;

    function DoBank: Boolean;
    begin
    end;


    begin
      Case Lowercase(Players[CurrentPlayer].Loc) of
        'banked':
        if WalkToTrees then
          Players[CurrentPlayer].Loc := 'at trees';
        'at trees':
        if ChopTrees then
          Players[CurrentPlayer].Loc := 'chopped trees';
        'chopped trees':
        if WalkToBank then
          Players[CurrentPlayer].Loc := 'at bank';
        'at bank':
        if DoBank then
          Players[CurrentPlayer].Loc := 'banked';
      end;
    end.

    Right?

    Thankyooo
    -Boom

  4. #4
    Join Date
    Feb 2009
    Location
    Irvine, CA
    Posts
    2,873
    Mentioned
    8 Post(s)
    Quoted
    138 Post(s)

    Default

    functions return a result, which can be any type that has been defined (so either something in SRL, reflection if your using it, obviously the default types like integers, booleans, and strings, and custom types). Booleans are commonly used to figure out if something actually happened. An example to tell if you opened the bank successfully would be the SRL function "BankScreen". By using booleans, you can decide when to log off and when to keep going.

    All you would need to do is modify your current procedures into functions, and add that case statement into a repeat..until(not(LoggedIn)) loop, and you then have a pseudo-state machine!

  5. #5
    Join Date
    Dec 2010
    Posts
    808
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Hmm, there you confused me, so you are saying do:
    Simba Code:
    function WalkToTrees: Boolean;
    begin
    //Walking stuff here
    Result := Players[CurrentPlayer].Loc := 'At Trees';
    end;

    Thankyoooo
    -Boom

  6. #6
    Join Date
    Feb 2009
    Location
    Irvine, CA
    Posts
    2,873
    Mentioned
    8 Post(s)
    Quoted
    138 Post(s)

    Default

    Functions can return something. Let's take a common function for an example: Random(). Random generates a number between 0 and whatever integer you feed into it. the number it generates is the result of the function random.

    In runescape script, functions that return booleans are commonly used to tell if something worked or not. At the end of the function, some other function of some sort is called to tell if the function carried out properly.

    Let's look at the OpenTheBank function from my cooker as an example:

    Simba Code:
    function OpenTheBank: Boolean;
    var
      CTS, H, x, y, i: Integer;
      TPA: TPointArray;
      ATPA: Array of TpointArray;
    begin
      Result := False;
      R_FindRandoms;
      if not(LoggedIn) then
        Exit;
      if BankScreen then
      begin
        Result := True;
        Exit;
      end;
      CTS := GetColorToleranceSpeed;
      SetColorToleranceSpeed(2);
      SetColorspeed2Modifiers(0.027, 0.031);
      FindColorsTolerance(TPA, 3817283, MSX1, MSY1, MSX2, MSY2, 14);
      SetColorToleranceSpeed(CTS);
      if (Length(TPA) < 1) then
      begin
        Logout;
        Exit;
      end;
      ATPA := TPAtoATPAEx(TPA, 35, 35);
      SortATPAFromFirstPoint(ATPA, IntToPoint(MSCX, MSCY));
      if ShowDebugging then
        DebugATPABounds(ATPA);
      H := Length(ATPA);
      for i := 0 to H do
      begin
        MiddleTPAEx(ATPA[i], x, y);
        MMouse(x, y, 4, 4);
        if WaitUptext('ank booth', 800) then
        begin
          ClickMouse2(False);
          Result := WaitOption('quickly', 800);
        end;
        if (Result or BankScreen) then
          Break;
      end;
      FFlag(0);
      Result := WaitFunc(@BankScreen, 20 + Random(25), 5000);
      Wait(600 + Random(60));
    end;


    See how on the second to last line, i call "Result := "SOMETHING""? WaitFunc is a function in SRL that calls the function (Defined like @Function) ever x number of seconds (the 2nd parameter) over and over until it either returns true or the total time is longer than the 3rd parameter (in ms). If it finds the Bank screen to be open, then the result is true.

    If the result is true, i know i can continue on with my script. However, if it returns false, i know that something went wrong, so the player needs to be logged out.

    Catch my drift?

  7. #7
    Join Date
    Dec 2010
    Posts
    808
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    I understand what you are talking about, but don't understand what you are suggesting xD
    Are you suggesting:
    Simba Code:
    Function Bank : Boolean;
    Begin
       if DoBankStuff then
       Result := WalkToTrees;
    End;
    ? :P

    -Boom

  8. #8
    Join Date
    Feb 2009
    Location
    Irvine, CA
    Posts
    2,873
    Mentioned
    8 Post(s)
    Quoted
    138 Post(s)

    Default

    no.

    depending on the location, it runs the function, and if the function returns true, then it sets the location to the next step.

  9. #9
    Join Date
    Dec 2010
    Posts
    808
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by TomTuff View Post
    no.

    depending on the location, it runs the function, and if the function returns true, then it sets the location to the next step.
    Ohhhhhh
    I get what you are suggesting.
    Ok.
    Do you have MSN, I might need some more help

    Thankyoooo
    -Boom
    Last edited by **BANNED The Man; 12-23-2010 at 11:43 PM.

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

    Default

    To be even better practice, the player.loc should be set inside the walking function.

  11. #11
    Join Date
    Dec 2010
    Posts
    808
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Dynamite View Post
    Hmm, there you confused me, so you are saying do:
    Simba Code:
    function WalkToTrees: Boolean;
    begin
    //Walking stuff here
    Result := Players[CurrentPlayer].Loc := 'At Trees';
    end;

    Thankyoooo
    -Boom
    Quote Originally Posted by Zyt3x View Post
    To be even better practice, the player.loc should be set inside the walking function.
    Like that ^ ?

    -Boom

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

    Default

    Correct

  13. #13
    Join Date
    Feb 2009
    Location
    Irvine, CA
    Posts
    2,873
    Mentioned
    8 Post(s)
    Quoted
    138 Post(s)

    Default

    Quote Originally Posted by Zyt3x View Post
    Correct
    Not correct, that always sets the results to true... so why make it a function at that point?

  14. #14
    Join Date
    Jan 2008
    Location
    10° north of Hell
    Posts
    2,035
    Mentioned
    65 Post(s)
    Quoted
    164 Post(s)

    Default

    Quote Originally Posted by TomTuff View Post
    Not correct, that always sets the results to true... so why make it a function at that point?
    ^ I agree and also You need a function to find where the player is currently.

    Take for instance a player starts the script.
    Players[CurrentPlayer].Loc is empty. (Unless you have the player specify where he or she is)
    So in the case
    Simba Code:
    case Players[CurrentPlayer].Loc of
      'Whatever1': DoSomething;
      'Whatever2': DoSomethingElse;
      else
        Players[CurrentPlayer].Loc := FindWhereImAt;
    end;

    Dg's Small Procedures | IRC Quotes
    Thank Wishlah for my nice new avatar!
    Quote Originally Posted by IRC
    [22:12:05] <Dgby714> Im agnostic
    [22:12:36] <Blumblebee> :O ...you can read minds

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

    Default

    Quote Originally Posted by TomTuff View Post
    Not correct, that always sets the results to true... so why make it a function at that point?
    Ow, yeah I misread his post.

    I meant
    Simba Code:
    if Result then
      Players[CurrentPlayer].Loc := 'At trees';

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
  •