Results 1 to 16 of 16

Thread: Dynamic integer

  1. #1
    Join Date
    Jan 2007
    Posts
    513
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Dynamic integer

    Hello,

    In my script I have an integer, Colorfind, which increases with 1 everytime a color is found. (Colorfind := Colorfind + 1

    Now I'm having two coordinates, cx & cy, where I store the founded coordinates in, but the color-coords have to be stored in a different cx & cy for each time the color was found.

    As Example:

    1) Color was found at 3, 4
    cx1 := 3
    cy1 := 4

    2) Color was found again at 7,9
    cx2 := 7
    cy2 := 9

    How do I make this 1 & 2 increase everytime my 'Colorfind' increases?

    Summary: Is there a way to have an integer like cx(+ value of other integer) ?
    Srl simply rocks.

  2. #2
    Join Date
    Oct 2006
    Location
    ithurtsithurtsithurtsithurts
    Posts
    2,930
    Mentioned
    7 Post(s)
    Quoted
    135 Post(s)

    Default

    The closest would be to have an array of TPoints, and increment the position within the array each time.

  3. #3
    Join Date
    Jan 2007
    Posts
    513
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Could you explain that a bit more?
    Srl simply rocks.

  4. #4
    Join Date
    Oct 2006
    Location
    ithurtsithurtsithurtsithurts
    Posts
    2,930
    Mentioned
    7 Post(s)
    Quoted
    135 Post(s)

    Default

    Sure. Here's an example:

    SCAR Code:
    program Example;
    var
      colorCoords: Array of TPoint;
      ColorFind: Integer;
    begin
      SetLength(colorCoords, 1);
      repeat
        colorCoords[ColorFind].X := random(20); //this would actually be whatever coords you find
        colorCoords[ColorFind].Y := random(20);
        Inc(ColorFind);
        SetLength(colorCoords, ColorFind + 1); //increase the size of the array
      until(False);
    end.

  5. #5
    Join Date
    Jan 2007
    Posts
    513
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Thank you so much for that!

    Is there a way to show all integers that have a color/number stored in them? (So all colorCoords that were changed from 0-value to something else)

    Edit: What I would like the program to do is, after it checked all the colors, is to click on each coordinate that had a color found.

    Example: ClickMouse(colorCoords1.x, colorCoords1.y, True); ClickMouse(colorCoords2.x, colorCoords2.y, True);
    Srl simply rocks.

  6. #6
    Join Date
    Oct 2006
    Location
    ithurtsithurtsithurtsithurts
    Posts
    2,930
    Mentioned
    7 Post(s)
    Quoted
    135 Post(s)

    Default

    Well, this could be done one of two ways. The first is the simplest, but it assumes that you're only increasing ColorFind (and the array's size) after you find a color. In that case, you'd just have to run through the array, kind of like this:
    SCAR Code:
    var
      i : integer;
    begin
    for i:= 0 to High(colorCoords) do
      Writeln(IntToStr(colorCoords[i].X) + ',' + IntToStr(colorCoords[i].Y));
    end.

    The second way is similar to the first, but it checks to make sure that the values are not 0.

    SCAR Code:
    var
      i : integer;
    begin
    for i:= 0 to High(colorCoords) do
      if ((colorCoords[i].X <> 0) or (colorCoords[i].Y <> 0)) then
        Writeln(IntToStr(colorCoords[i].X) + ',' + IntToStr(colorCoords[i].Y));
    end.
    Last edited by senrath; 10-18-2009 at 02:25 PM.

  7. #7
    Join Date
    Jan 2007
    Posts
    513
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    The function with the if-statement gives me 2 errors:

    Line 83: [Error] (83:23): Syntax error in script
    Line 83: [Error] (83:23): Closing parenthesis in script
    Srl simply rocks.

  8. #8
    Join Date
    Oct 2006
    Location
    ithurtsithurtsithurtsithurts
    Posts
    2,930
    Mentioned
    7 Post(s)
    Quoted
    135 Post(s)

    Default

    My bad, I made a mistake. I edited my post before, so try that statement now.

  9. #9
    Join Date
    Jan 2007
    Posts
    513
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Woot, it works!

    I have another problem though:
    It writes the coordinates perfectly in the debug box, but when I tell it to move to the coordinates, it gives me an out of range error

    MoveMouse(colorCoords[i].X , colorCoords[i].Y);

    though the coordinates exists, as the program writes correctly them in the debugbox;

    Sorry for my many questions, thanks so much for all your help!
    Srl simply rocks.

  10. #10
    Join Date
    Oct 2006
    Location
    ithurtsithurtsithurtsithurts
    Posts
    2,930
    Mentioned
    7 Post(s)
    Quoted
    135 Post(s)

    Default

    Post the code that's causing the error?

  11. #11
    Join Date
    Jan 2007
    Posts
    513
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    procedure ClickFoundColors;
    begin
    for i:= 0 to High(colorCoords) do
    if ((colorCoords[i].X <> 0) or (colorCoords[i].Y <> 0)) then
    Writeln(IntToStr(colorCoords[i].X) + ',' + IntToStr(colorCoords[i].Y));
    MoveMouse(colorCoords[i].X , colorCoords[i].Y); -> here is the error
    end;

    I have the colorCoords-storing thingie in another procedure, you need that too?
    Srl simply rocks.

  12. #12
    Join Date
    Feb 2007
    Location
    Het ademt zwaar en moedeloos vannacht.
    Posts
    7,211
    Mentioned
    26 Post(s)
    Quoted
    72 Post(s)

    Default

    You forgot a begin/end in your code

    SCAR Code:
    procedure ClickFoundColors;
    begin
      for i := 0 to high (colorCoords) do
        if ((colorCoords[i].X <> 0) or (colorCoords[i].y <> 0)) then
        begin
          Writeln(IntToStr(colorCoords[i].X) + ',' + IntToStr(colorCoords[i].Y));      
          MoveMouse(colorCoords[i].X , colorCoords[i].Y);
        end;
    end;
    Last edited by Markus; 10-18-2009 at 02:38 PM.
    I made a new script, check it out!.

  13. #13
    Join Date
    Oct 2006
    Location
    ithurtsithurtsithurtsithurts
    Posts
    2,930
    Mentioned
    7 Post(s)
    Quoted
    135 Post(s)

    Default

    No, you need to make a slight change:
    SCAR Code:
    procedure ClickFoundColors;
    begin
      for i:= 0 to High(colorCoords) do
      if ((colorCoords[i].X <> 0) or (colorCoords[i].Y <> 0)) then
        begin//add this
          Writeln(IntToStr(colorCoords[i].X) + ',' + IntToStr(colorCoords[i].Y));
          MoveMouse(colorCoords[i].X , colorCoords[i].Y);
        end;//add this
    end;

    Edit: Ninja'd!

  14. #14
    Join Date
    Jan 2007
    Posts
    513
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Woot, it works!

    I have one more little problem: The script clicks too fast, my game can't record it Is there a way to make it wait 25 ms between each click or so?
    Srl simply rocks.

  15. #15
    Join Date
    Oct 2006
    Location
    ithurtsithurtsithurtsithurts
    Posts
    2,930
    Mentioned
    7 Post(s)
    Quoted
    135 Post(s)

    Default

    Um, just put a Wait(25); after the click in your script.

  16. #16
    Join Date
    Jan 2007
    Posts
    513
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Oh, didn't know that would work for all clicks.

    Thank you so much for all your help Senrath!
    Srl simply rocks.

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
  •