Home > Net >  Save Coordinates in a Array
Save Coordinates in a Array

Time:04-05

I would like to save found data from a pixel search in an array and have it output again, but I have no idea how to start.

That is basicly my current Search function:

object result = au3.PixelSearch(77, 270, 190, 298, 0x29343F, 5);

if (result.ToString() != "1")
{
    object[] resultCoord = (object[])result;
    au3.MouseClick("LEFT", (int)resultCoord[0], (int)resultCoord[1], 1, 5);
}

And the reason for the array is, that i want to expand it.
Example: After Pixel found, mouse is already moved and clicked once, then it should save the coordinates in a array and if the pixel is not longer visible, then it should expand the function and click again at the same coordinates. Its for me not necessary that the coordinates get saved by mouseclick, it can also saved by the if statement

if (result.ToString() != "1")

How is this possible?

CodePudding user response:

Ok, lets use a List (remember using System.Collections.Generic; on the upper part of your code :P)

public List<object> savedCoords = new List<object>(); //declare this out of your search function or it will be overwrited each search;

Then you can add your search result to the list:

object result = au3.PixelSearch(77, 270, 190, 298, 0x29343F, 5);

if (result.ToString() != "1")
{
    savedCoords.Add(result); //<--HERE
    object[] resultCoord = (object[])result;
    au3.MouseClick("LEFT", (int)resultCoord[0], (int)resultCoord[1], 1, 5);
}

If you want to search the list tell me the structure of the object returned by au3.PixelSearch and I'll make a lambda to do it and edit the eanswer

CodePudding user response:

You should be using a better description of your pixel coordinates. For example a system.Drawing.Point, but you might also create your own equivalent type.

Then you can just use a list to keep multiple points

var myList = new List<Point>();
myList.Add(new Point(xCoordinate, yCoordinate));

It is not clear to me how you are getting your coordinates, but whenever you find yourself using object you should really stop and think if that is the best type you can use for your problem. Same thing with strings, they are for representing text, not arbitrary objects.

  • Related