Results 1 to 6 of 6

Thread: How would I incorporate a created function into a procedure?

  1. #1
    Join Date
    Jan 2012
    Posts
    76
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default How would I incorporate a created function into a procedure?

    I've been having troubles using a function I've created and putting it into a procedure. Basically I want a procedure that If it finds the character in a certain area then it carries out the function I created.

    My main problem I think is on the logical side. I know how to find the character I just can't seem to include the function in a procedure without causing an error or two. My function is both Boolean and involves integers (see below for example) and I just don't know how to integrate that into a procedure. Please help?

    Simba Code:
    function FindObstaclePipe(Var X, Y : Integer): Boolean;
    var
      TPA : TPointArray;
      ATPA : T2DPointArray;
      Retry, I, H : Integer;
    Begin
      FindColorsSpiralTolerance(MSCX, MSCY, TPA, 0, MSX1, MSY1, MSX2, MSY2, 15);
      ATPA := TPAtoATPA(TPA, 25);
      If Length(ATPA) = 0 Then
        Exit;
      H := High(ATPA);
      For I := 0 To H Do
      Begin
      repeat
      inc(Retry);
        MiddleTPAEx(ATPA[I], X, Y);
        MMouse(X, Y, 3, 3);
        Wait(50 + Random(50));
        If IsUpText('queeze') Then
        Begin
          Writeln('Found Obstacle Pipe!');
          GetMousePos(X, Y);
          Mouse(x, y, 0, 0, 1);
          Result := True;
          Exit;
        End;
        until((Retry=10) or (Result=True));
      End;
    End;

    Or, alternatively based off some good advice I was considering changing this into a TP function instead of a integer function in which case it would look like:

    Simba Code:
    function FindObstaclePipe(Var TP : TPoint): Boolean;
    var
      TPA : TPointArray;
      i, x, y : Integer;
    begin
      FindColorsSpiralTolerance(MSCX, MSCY, TPA, PipeColor, MSX1, MSY1, MSX2, MSY2, 15);
      If Length(TPA) = 0 Then
        Exit;
      for i := 0 To high(TPA) do
      begin
        MMouse(TPA[i].x, TPA[i].y, 3, 3);
        Wait(50 + Random(50));
        If WaitUpText('queeze', 200+Random(200)) Then
        begin
          Writeln('Found Obstacle Pipe!');
          ClickMouse2(mouse_Left);
          GetMousePos(x, y);
          TP := Point(x, y);
          Result := True;
          Wait(5000+random(2000));
        end;

       end;
    end;

    Thank you in advance!

  2. #2
    Join Date
    Mar 2006
    Location
    Behind you
    Posts
    3,193
    Mentioned
    61 Post(s)
    Quoted
    63 Post(s)

    Default

    Check out the link in my sig for info on making functions

    "Sometimes User's don't need the Answer spelled out with Code. Sometimes all they need is guidance and explanation of the logic to get where they are going."

  3. #3
    Join Date
    May 2007
    Location
    Waterloo, Ontario, Canada
    Posts
    1,008
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    What you want to do is have a procedure called doObstacle1 or whatever, and calling it like so.. Don't forget that you need an if case, to pass the boolean which is what type that function is of:

    Simba Code:
    if(findObstacle1()) then
          begin
               /todocode
          end;

    In this example, I am assuming findObstacle1() is a Function, like in your case which it would be FindObstaclePipe, or whatever the name was.



  4. #4
    Join Date
    Jan 2012
    Posts
    76
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Thanks for the responses guys!

    Check out the link in my sig for info on making functions
    Thanks, I looked over the guide before posting this and it's a great guide, but I'm still a bit confused. I can't seem to wrap my head around the concept--I'm not too concerned about input/output, I just want to be able to have a procedure in which if in a certain location then the procedure will call the function, so using the function from the first post it would maybe look something like:

    Simba Code:
    Procedure ObstaclePipe(X, Y:integer);

    Var
    FindObstaclePipe:Boolean;
    begin
    if (Character Location=1) then // with the '1' coming from the result of another function
      begin
         FindObstaclePipe(X, Y);
      end;
    end;

    That obviously isn't right, but that's the sort of general idea I'm going for--I'm just having problems with utilizing variables and constants I guess--could you give me an example of how a procedure like that would be set up?

    What you want to do is have a procedure called doObstacle1 or whatever, and calling it like so.. Don't forget that you need an if case, to pass the boolean which is what type that function is of:

    Simba Code:
    if(findObstacle1()) then
    begin
    /todocode
    end;

    In this example, I am assuming findObstacle1() is a Function, like in your case which it would be FindObstaclePipe, or whatever the name was.
    Thank you for the help! I still am unsure though. I continually get type mismatch errors no matter how I try to shape the procedure (I'm trying to shape a procedure more than shape the main loop I think). Along with the response to Brak, what would this procedure look like?

    thank you guys

  5. #5
    Join Date
    Jan 2012
    Location
    Calgary, AB, Canada
    Posts
    1,819
    Mentioned
    5 Post(s)
    Quoted
    120 Post(s)

    Default

    This is how I implement a finding function into my maple chopper:


    The function:
    Simba Code:
    function FindMaple(Var X,Y: Integer): Boolean;
    var
      CTS: Integer;
      TPA: TPointArray;
        begin
          Result := False;
            CTS := GetColorToleranceSpeed;
              ColorToleranceSpeed(2);
                SetColorSpeed2Modifiers(0.1118890554722637, 0.3301270417422868);
                  FindColorsSpiralTolerance(MSCX, MSCY, TPA, 2244448, MSX1, MSY1, MSX2, MSY2, 7);
                    ColorToleranceSpeed(CTS);

                    if (Length(TPA) < 1) then
                    Exit;

                MMouse(TPA[0].X, TPA[0].Y, 5, 5);

                  if WaitUpText('hop', 250) then
                    begin
                      GetMousePos(X, Y);
                    Mouse(x, y, 0, 0, False);
                  ChooseOption('Chop');
                Result := True;
              Exit;
          end;
    end;

    And part of the procedure:

    Simba Code:
    procedure MapleChopp;
    begin
      case Banking of
      'no':
      begin
      MakeCompass('N');
        SetAngle(SRL_ANGLE_HIGH);
          wait(200+random(400));

            FindNormalRandoms;
              if FindMaple(x, y) then --> finding part
                begin
                  Writeln('Tree Has Been Found');
                    Wait(10+random(20));
                      Mouse(x,y,4,4,true)
                        Wait(10+random(45));

                      if (Cutting) then
                    Antiban;

                end else Writeln('Cannot find Tree');
          repeat
            wait(50+random(100));
      Until(InvFull);
      DropAll;
    end;
    end;

    Hope this helped
    Current Project: Retired

  6. #6
    Join Date
    Jan 2012
    Posts
    76
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Hope this helped
    Thank you it definitely did!

    I however am still having problems getting this to compile...
    Simba Code:
    procedure WhereWeAt;
    var

    i:integer;
    tooAgilityCourse:TStringArray;


    begin
    tooAgilityCourse:=['21:45:6:2:7:65:38:2:7:56:55:2:7:78:98:2:7:44:107:5:7:93:79:5:7:89:100', '23:93:9:2:7:120:89:2:7:128:72:2:7:78:123:5:7:59:88:5:7:63:84:5:7:68:79:5:7:64:134:5:7:64:142:5:7:72:134', '21:52:5:2:7:65:77:2:7:44:60:5:7:118:71:5:7:126:62:5:7:122:67', '12:74:2:2:7:107:89:2:7:128:106', '8:89:1:2:7:41:118', '30:128:1:2:7:110:109', '14:68:8:5:7:33:74:5:7:37:90:5:7:16:90:5:7:29:86:5:7:45:82:5:7:45:102:5:7:37:110:5:7:37:98', '22:115:8:5:7:12:55:5:7:101:86:5:7:97:98:5:7:85:102:5:7:105:102:5:7:113:94:5:7:105:122:5:7:113:114', '15:98:9:5:7:20:119:5:7:80:119:5:7:76:128:5:7:88:127:5:7:40:51:5:7:32:47:5:7:24:43:5:7:141:66:5:7:145:82', '41:140:8:5:7:88:115:5:7:80:112:5:7:84:103:5:7:44:28:5:7:48:23:5:7:96:31:5:7:104:35:5:7:88:27', '78:149:4:2:7:62:144:5:7:128:48:5:7:124:57:5:7:132:60', '36:48:7:2:7:11:84:2:7:27:92:2:7:46:88:2:7:66:77:5:7:52:118:5:7:48:127:5:7:60:126:4:27:45:43:44:57:60:15:61'];
    begin
      if ObjDTM_InArea(tooAgilityCourse[0], True) then
        WriteLn('Checking to see if you just teled to Wilderness..');

        WriteLn('Good, you are in the wilderness!');
        for I :=0 to 10 do
        begin

        Writeln(i);
        ObjDTM_Walk(tooAgilityCourse[i], 0, 100, 80, True);
        end;
    //FindObstaclePipe
      if ObjDTM_InArea('79:81:5:2:7:73:61:2:7:101:34:5:7:22:87:5:7:26:79:10:7:78:102:4:70:72:90:71:91:88:71:88', True) then
        begin
          if FindObstaclePipe(x, y) then
            While(Wait(5000+random(4000))) do
              RandomTab;
        end;
    //Find Rope Swing
      if ObjDTM_InArea('79:81:5:2:7:70:109:2:7:98:81:5:7:112:72:5:7:116:67:5:7:112:56:4:72:61:92:60:92:89:72:90', True) then
        begin
          if FindRopeSwing(X, Y) then
            While(Wait(4000+random(2000))) do
              RandomTab;
        end;
    //Find Stepping Stone
      if ObjDTM_InArea('79:81:7:2:7:95:113:2:7:67:142:5:7:120:58:5:7:116:70:5:7:116:79:5:7:108:87:5:7:129:86:5:56:48:56:78:96:79:83:66:84:49', True) then
        begin
          if FindSteppingStone(X, Y) then
            While(Wait(4000+random(2000))) do
              RandomTab;
        end;
    //Find bridge
      If ObjDTM_InArea('78:80:4:2:7:111:63:2:7:107:81:2:7:82:93:10:7:86:138:4:69:68:82:68:89:96:72:97', True) then
        begin
          MakeCompass('S');
          if FindBridge(X, Y) then
          MakeCompass('N');
            While(Wait(5000+random(3451))) do
              RandomTab;
        end;
    //Find Cliff
      if ObjDTM_InArea('80:80:6:1:7:36:105:1:7:16:98:2:7:112:50:5:7:61:75:5:7:64:68:10:7:116:90:4:68:73:97:73:97:86:69:85', True) then
        begin
          MakeCompass('S');
          if FindCliff(X, Y) then
          MakeCompass('N');
            While(Wait(4000+random(2565))) do
              RandomTab;
        end;
      end;
    end;

    Still rough and more of an example then a final procedure but I can't seem to get this to compile. It says each of my functions is an "unknown identifier" except all the functions are written elsewhere in the script and declared in the form of:
    Simba Code:
    function FindObstaclePipe(Var X, Y : Integer): Boolean;

    I can get your mega maple chopper to compile, but mine just won't compile and I don't know why despite the fact the functions are declared in exactly the same form. Any suggestions?

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
  •