0

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?

4
  • And why not use a List<object> instead an array? Commented Apr 5, 2022 at 8:46
  • because iam a roockie and dont know the benefits of that.I would be very happy about a code example :) Commented Apr 5, 2022 at 8:48
  • 2
    What Type does au3.PixelSearch really return? Probably something better than "object" Commented Apr 5, 2022 at 9:12
  • What are you targeting: Winforms, WPF, ASP..? YOU should always TAG your questions correctly so one can see it on the questions page! - Winforms: A List<PointF> comes to mind as the better data structure. (Much easier to expand etc..) Commented Apr 5, 2022 at 9:52

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.