Results 1 to 11 of 11

Thread: For..To..Do

  1. #1
    Join Date
    Mar 2008
    Location
    Look behind you.
    Posts
    795
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default For..To..Do

    For the past few days much of my free time has been spent working on a little project of mine. Whether it will be completed or not is another story. Currently problems are already being encountered when trying to run through a for..to..do loop. I need the bot to randomly choose the skin color, but first it needs to detect the current skin color. So I set this up:
    Simba Code:
    function SSkin: boolean;
    var
      GPos: Array of TPoint;
      i, Skin: Integer;
    begin
      GPos[0] := Point(487, 27);
      GPos[1] := Point(507, 27);
      GPos[2] := Point(530, 27);
      GPos[3] := Point(558, 27);
      GPos[4] := Point(563, 27);
      GPos[5] := Point(587, 27);
      GPos[6] := Point(614, 27);
      GPos[7] := Point(640, 27);
      GPos[8] := Point(663, 27);
      GPos[9] := Point(687, 27);
      GPos[10] := Point(713, 27);
      GPos[11] := Point(739, 27);
      for i:= 0 to 11 do
      begin
        if (CountColorTolerance(14859158, GPos[i].x, GPos[i].y, GPos[i].x+1, GPos[i].y+1, 3) > 0) then
          Constant := GPos[i];
        else
          Continue;
      end;
    end;
    *NOTE: Constant is a global variable in my script-
    Simba Code:
    Constant: variant;
    It will be used to save the current coords where the outline color is found.

    Technically it should compile. However, my rusty scripting is at fault. I do not understand why it does not work!(Gives me a runtime error.) Could someone please explain to me please? There is no need for code snippets unless it is an example. I'll include credits where it is needed to whoever helps me out.

  2. #2
    Join Date
    Jun 2007
    Location
    La Mirada, CA
    Posts
    2,484
    Mentioned
    1 Post(s)
    Quoted
    3 Post(s)

    Default

    What line of code do you get the runtime error at? Do a little debugging to find your problem.

    "Failure is the opportunity to begin again more intelligently" (Henry Ford)


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

    Default

    You have to set the length of your array first perhaps.

    SCAR Code:
    SetLength(GPos, 12)

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

    Default

    You need to SetLength, when your at the end of a for loop there is no reason to do continue, and when you exclude begin end inside of a if else you remove the ; after the command before else.

    Not realy needed but Array of TPoint can be TPointArray
    There was also no use for the integer Skin

    Simba Code:
    function SSkin: boolean;
    var
      GPos: TPointArray;
      i: Integer;
    begin
      SetArrayLength(GPos, 12);
      GPos[0] := Point(487, 27);
      GPos[1] := Point(507, 27);
      GPos[2] := Point(530, 27);
      GPos[3] := Point(558, 27);
      GPos[4] := Point(563, 27);
      GPos[5] := Point(587, 27);
      GPos[6] := Point(614, 27);
      GPos[7] := Point(640, 27);
      GPos[8] := Point(663, 27);
      GPos[9] := Point(687, 27);
      GPos[10] := Point(713, 27);
      GPos[11] := Point(739, 27);
      for i:= 0 to 11 do
        if (CountColorTolerance(14859158, GPos[i].x, GPos[i].y, GPos[i].x+1, GPos[i].y+1, 3) > 0) then
          Constant := GPos[i];
    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

  5. #5
    Join Date
    Mar 2008
    Location
    Look behind you.
    Posts
    795
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Quote Originally Posted by Dgby714 View Post
    You need to SetLength, when your at the end of a for loop there is no reason to do continue, and when you exclude begin end inside of a if else you remove the ; after the command before else.

    Not realy needed but Array of TPoint can be TPointArray
    There was also no use for the integer Skin

    Simba Code:
    function SSkin: boolean;
    var
      GPos: TPointArray;
      i: Integer;
    begin
      SetArrayLength(GPos, 12);
      GPos[0] := Point(487, 27);
      GPos[1] := Point(507, 27);
      GPos[2] := Point(530, 27);
      GPos[3] := Point(558, 27);
      GPos[4] := Point(563, 27);
      GPos[5] := Point(587, 27);
      GPos[6] := Point(614, 27);
      GPos[7] := Point(640, 27);
      GPos[8] := Point(663, 27);
      GPos[9] := Point(687, 27);
      GPos[10] := Point(713, 27);
      GPos[11] := Point(739, 27);
      for i:= 0 to 11 do
        if (CountColorTolerance(14859158, GPos[i].x, GPos[i].y, GPos[i].x+1, GPos[i].y+1, 3) > 0) then
          Constant := GPos[i];
    end;
    Problem solved! My variant variable does not want to work with TPoints, so I created a local var to take care of business. Thanks to you and ZephyrsFury not only did my problem go away, but I also have neater code.

  6. #6
    Join Date
    Jan 2008
    Location
    Ontario, Canada
    Posts
    7,805
    Mentioned
    5 Post(s)
    Quoted
    3 Post(s)

    Default

    Why not declare it using the X = [x1, x2] syntax?

    It cleans up your code, as well it allows you to quickly add points. Also, in your for loop, adding in high(X) rather than using static numbers might be a good plan.
    Writing an SRL Member Application | [Updated] Pascal Scripting Statements
    My GitHub

    Progress Report:
    13:46 <@BenLand100> <SourceCode> @BenLand100: what you have just said shows you 
                        have serious physchological problems
    13:46 <@BenLand100> HE GETS IT!
    13:46 <@BenLand100> HE FINALLY GETS IT!!!!1

  7. #7
    Join Date
    Mar 2008
    Location
    Look behind you.
    Posts
    795
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Thanks Nava2, here's my procedure so far:
    Simba Code:
    {SelectSkin- Thanks to Dgby714, ZephyrsFury, and Nava2 for help with this}
    procedure SSkin;
    var
      GPos: TPointArray;
      i, Skin: Integer;
      C : TPoint;
    begin
      if not(CCScreen) then
        Exit;
      SetLength(GPos, 12);
      GPos := [Point(463, 27), Point(486, 27), Point(515, 27), Point(538, 27),
               Point(561, 27), Point(587, 27), Point(614, 27), Point(640, 27),
               Point(663, 27), Point(687, 27), Point(713, 27), Point(739, 27)];
      for i:= Low(GPos) to High(GPos) do
        if (CountColorTolerance(14859158, GPos[i].x, GPos[i].y, GPos[i].x+1, GPos[i].y+1, 63) > 0) then
          C := GPos[i];
      case (C.x) of
        463: Constant := 0;
        486: Constant := 1;
        515: Constant := 2;
        538: Constant := 3;
        561: Constant := 4;
        587: Constant := 5;
        614: Constant := 6;
        640: Constant := 7;
        663: Constant := 8;
        687: Constant := 9;
        713: Constant := 10;
        739: Constant := 11;
      end;
      Skin := Random(11);
      if (Skin = Constant) then
        if (Constant = 11) then
          Dec(Skin)
        else
        if (Constant > -1) then
          Inc(Skin);
      Mouse(GPos[Skin].x, GPos[Skin].y+2+random(4), 5, 5, True);
      Wait(356+random(653));
    end;
    The case seems large, I'll see what I can do with it.
    E:
    Simba Code:
    {SelectSkin- Thanks to Dgby714 and ZephyrsFury for help with this}
    procedure SSkin;
    var
      GPos: TPointArray;
      i, Skin: Integer;
      SkinID: TIntegerArray;
      C : TPoint;
    begin
      if not(CCScreen) then
        Exit;
      SetLength(GPos, 12);
      GPos := [Point(463, 27), Point(486, 27), Point(515, 27), Point(538, 27),
               Point(561, 27), Point(587, 27), Point(614, 27), Point(640, 27),
               Point(663, 27), Point(687, 27), Point(713, 27), Point(739, 27)];
      SetLength(SkinID, 12);
      SkinID := [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
      for i:= Low(GPos) to High(GPos) do
        if (CountColorTolerance(14859158, GPos[i].x, GPos[i].y, GPos[i].x+1, GPos[i].y+1, 63) > 0) then
        begin
          C := GPos[i];
          Constant := SkinID[i];
        end;
      Skin := Random(11);
      if (Skin = Constant) then
        if (Constant = 11) then
          Dec(Skin)
        else
        if (Constant > -1) then
          Inc(Skin);
      Mouse(GPos[Skin].x, GPos[Skin].y+2+random(4), 5, 5, True);
      Wait(356+random(653));
    end;
    Made it shorter!
    Last edited by DeSnob; 10-30-2010 at 09:52 PM.

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

    Default

    Simba Code:
    procedure SSkin;
    var
      GPos: TIntegerArray;
      i, Skin: Integer;
    begin
      if not(CCScreen) then
        Exit;
      SetLength(GPos, 12);
      GPos := [463, 486, 515, 538, 561, 587, 614, 640, 663, 687, 713, 739];
      for i := Low(GPos) to High(GPos) do
        if (CountColorTolerance(14859158, GPos[i], 27, GPos[i] + 1, 28, 63) > 0) then
          Constant := i;
      Skin := Random(11);
      if (Skin = Constant) then
        if ((Constant > -1) and (not (Constant = 11))) then
          Inc(Skin)
        else
          Dec(Skin);
      Mouse(GPos[Skin], 29, 5, 9, True);
      Wait(356 + Random(653));
    end;
    Last edited by Dgby714; 10-30-2010 at 10:10 PM.

    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

  9. #9
    Join Date
    Mar 2008
    Location
    Look behind you.
    Posts
    795
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Thank you very much.

  10. #10
    Join Date
    May 2007
    Location
    Everywhere
    Posts
    1,428
    Mentioned
    0 Post(s)
    Quoted
    2 Post(s)

    Default

    Just out of curiosity:
    Simba Code:
    SetLength(GPos, 12); // <--
      GPos := [463, 486, 515, 538, 561, 587, 614, 640, 663, 687, 713, 739];
    Should it not work if we eliminated the top line? I might be wrong... IIRC defining a TypeArray set it's length automatically?

  11. #11
    Join Date
    Mar 2008
    Location
    Look behind you.
    Posts
    795
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Quote Originally Posted by cstrike View Post
    Just out of curiosity:
    Simba Code:
    SetLength(GPos, 12); // <--
      GPos := [463, 486, 515, 538, 561, 587, 614, 640, 663, 687, 713, 739];
    Should it not work if we eliminated the top line? I might be wrong... IIRC defining a TypeArray set it's length automatically?
    That was an issue before, but yes theoretically it should work without it.

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
  •