Sign in to follow this  
Followers 0
shazar

Build a box to search after pixelsearch results

12 posts in this topic

Hello!

I'm new to scripting... I've been searching for this for about 3 hours now and can't find it... so I'm just going to ask!

I can use pixelsearch funtion to find the pixel I want and activate off of it with mouse clicks.

What I need instead is use the coords from pixelsearch to build a NEW box to perform a secondary pixelsearch in.

So... search a bigger area for a pixel color. Build a box around that and search for another pixel color and activate off of that.

Thanks for any advice!

Patrick

Share this post


Link to post
Share on other sites

Pre Define:  $BoxLength, $BoxHeight, $PixelLocation

$BoxLeft = $PixelLocation - $BoxLength / 2
$BoxTop = $PixelLocation - $BoxHeight / 2

Okay, I hope you know what to do with that. In addition to make the box bigger just change the $BoxLength and $BoxHeight


Offering any help to anyone (to my capabilities of course)Want to say thanks? Click here! [quote name='Albert Einstein']Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.[/quote][quote name='Wolvereness' date='7:35PM Central, Jan 11, 2005']I'm NEVER wrong, I call it something else[/quote]

Share this post


Link to post
Share on other sites

Pre Define:  $BoxLength, $BoxHeight, $PixelLocation

$BoxLeft = $PixelLocation - $BoxLength / 2
$BoxTop = $PixelLocation - $BoxHeight / 2

Okay, I hope you know what to do with that. In addition to make the box bigger just change the $BoxLength and $BoxHeight

<{POST_SNAPBACK}>

I don't really know what to do with it... but I'll try and figure it out :idiot:

Thanks for the responce!

Share this post


Link to post
Share on other sites

Pre Define:  $BoxLength, $BoxHeight, $PixelLocation

$BoxLeft = $PixelLocation - $BoxLength / 2
$BoxTop = $PixelLocation - $BoxHeight / 2

Okay, I hope you know what to do with that. In addition to make the box bigger just change the $BoxLength and $BoxHeight

<{POST_SNAPBACK}>

K I tried this...

$coor = PixelSearch (50, 300, 1000, 550, 0xB28D54, 25, 4)

$BoxLength = 50

$BoxHeight = 70

$PixelLocation = $coor[0], $coor[1]

$BoxLeft = $PixelLocation - $BoxLength / 2

$BoxTop = $PixelLocation - $BoxHeight / 2

$BoxRight = $PixelLocation + $BoxLength / 2

$BoxBottom = $PixelLocation + $BoxHeight / 2

$coord = PixelSearch ($BoxLeft, $BoxTop, $BoxRight, $BoxBottom, 0xFFFFFF,

25, 4)

-------------

Says Error: Subscript used with Non-Array Variable!

I know I'm missing something.. obviously I am not turning the first pixelsearch coords into something I can use for $pixelLocation variables....

More help?

Search a box for a pixel (which I can do...) use those coords to center a box around and search that box for a different pixelsearch.

Thanks for anything else you provide!

Patrick

Share this post


Link to post
Share on other sites

K I tried this...

$coor = PixelSearch (50, 300, 1000, 550, 0xB28D54, 25, 4)

$BoxLength = 50

$BoxHeight = 70

$PixelLocation = $coor[0], $coor[1]

$BoxLeft = $PixelLocation - $BoxLength / 2

$BoxTop = $PixelLocation - $BoxHeight / 2

$BoxRight = $PixelLocation + $BoxLength / 2

$BoxBottom = $PixelLocation + $BoxHeight / 2

$coord = PixelSearch ($BoxLeft, $BoxTop, $BoxRight, $BoxBottom, 0xFFFFFF,

25, 4)

-------------

Says Error: Subscript used with Non-Array Variable!

===============================================

You should have also received a syntax error for the "$PixelLocation =" line. Eliminate that line and do the following:

$BoxLeft = $coor[0] - $BoxLength / 2

$BoxTop = $coor[1] - $BoxHeight / 2

[...]


Phillip

Share this post


Link to post
Share on other sites

Always use error checking.

Try this:

$coor = PixelSearch (50, 300, 1000, 550, 0xB28D54, 25, 4)
If NOT @error Then
   $BoxLength = 50
   $BoxHeight = 70
      
   $BoxLeft = $coor[0] - $BoxLength / 2
   $BoxTop = $coor[1] - $BoxHeight / 2
   
   $BoxRight = $PixelLocation + $BoxLength / 2
   $BoxBottom = $PixelLocation + $BoxHeight / 2
   
   $coord = PixelSearch ($BoxLeft, $BoxTop, $BoxRight, $BoxBottom, 0xFFFFFF, 25, 4)
EndIf

Share this post


Link to post
Share on other sites

Always use error checking.

Try this:

$coor = PixelSearch (50, 300, 1000, 550, 0xB28D54, 25, 4)
If NOT @error Then
   $BoxLength = 50
   $BoxHeight = 70
      
   $BoxLeft = $coor[0] - $BoxLength / 2
   $BoxTop = $coor[1] - $BoxHeight / 2
   
   $BoxRight = $PixelLocation + $BoxLength / 2
   $BoxBottom = $PixelLocation + $BoxHeight / 2
   
   $coord = PixelSearch ($BoxLeft, $BoxTop, $BoxRight, $BoxBottom, 0xFFFFFF, 25, 4)
EndIf

<{POST_SNAPBACK}>

That won't work! You have to do the same thing to $BoxRight and $BoxBottom as done to $BoxLeft and $BoxTop.

Phillip

Share this post


Link to post
Share on other sites

I'm just editing your scripts.

I added: If NOT @error

That's what my post was about.

Share this post


Link to post
Share on other sites

Thank you for your replies!

I can get it to outline the box for me with:

$coor = PixelSearch (50, 300, 1000, 550, 0x194C61, 25, 4)

If NOT @error Then

$BoxLength = 100

$BoxHeight = 70

$BoxLeft = $coor[0] - $BoxLength / 2

$BoxTop = $coor[1] - $BoxHeight / 2

$BoxRight = $coor[0] + $BoxLength / 2

$BoxBottom = $coor[1] + $BoxHeight / 2

MouseMove ($BoxLeft, $BoxTop)

MouseMove ($BoxRight, $BoxTop)

MouseMove ($BoxRight, $BoxBottom)

MouseMove ($BoxLeft, $BoxBottom)

EndIf

So this part works, find the pixel and use the $box to define a box around it. Now I get this other problem when run this:

$coor = PixelSearch (50, 300, 1000, 550, 0x194C61, 26, 4)

If NOT @error Then

$BoxLength = 100

$BoxHeight = 70

$BoxLeft = $coor[0] - $BoxLength / 2

$BoxTop = $coor[1] - $BoxHeight / 2

$BoxRight = $coor[0] + $BoxLength / 2

$BoxBottom = $coor[1] + $BoxHeight / 2

$coord = PixelSearch ($BoxLeft, $BoxTop, $BoxRight, $BoxBottom, 0xFFFFFF, 25, 1)

EndIf

If UBound($coord)>1 Then

MouseClick("right", $coord[0], $coord[1], 1, 3)

Sleep(1000)

MouseClick("right")

Sleep(1000)

ExitLoop

Else

Sleep(1000)

$dif = TimerDiff($start)

If $dif > 30000 Then

ExitLoop

EndIf

EndIf

WEnd

WEnd

This isn't the complete script but this is just the part I'm having trouble with. The error I get is:

If UBound($coord)>1 Then

If UBound(^ERROR

Error: Viariable used without being declared.

I don't get it cause I am declaring it with just before it... its like it is skipping it or something...

Thanks for anyhelp!

Patrick

Share this post


Link to post
Share on other sites

If UBound($coord)>1 Then

If UBound(^ERROR

Error: Viariable used without being declared.

You switched from "$coor" to "$coord", and when the pixel search does not find the color, the "if" statement is skipped and $coord is never defined. Since it's not defined, the UBound function fails on $coord. If you need it defined regardless of the pixel search results, define it in an "Else" clause of the "If" statement.

Actually, and I could easily be wrong, I think the stuff done by the statement "If UBound($coord) > 1" could all be done in the "If Not @error" section of your code, with an "Else" clause added to do the exitloop stuff.


Phillip

Share this post


Link to post
Share on other sites

Okey.. having no program experience is really holding me back here... I'm sure I have all the pieces for what i am trying to do, but putting them together is really giving me a headache.

This is all part of another script that I am trying to edit to make better. The orginal one searched the screen until it found a pixel color and then acted upon it (clicked on it) or if it didn't detect it in time would restart the search.

I figured I could make it better if I detected first where the pixel color change was likely to show up and define a smaller search area around that point.

With the help here so far I can find the area that I need to search around:

$coord1 = PixelSearch (50, 300, 1000, 550, 0xCAA880, 26, 4)

I can define a new search area to do my next pixel search:

$BoxLength = 100

$BoxHeight = 70

$BoxLeft = $coord1[0] - $BoxLength / 2

$BoxTop = $coord1[1] - $BoxHeight / 2

$BoxRight = $coord1[0] + $BoxLength / 2

$BoxBottom = $coord1[1] + $BoxHeight / 2

And I can search the new area for my pixel change:

$coord2 = PixelSearch ($BoxLeft, $BoxTop, $BoxRight, $BoxBottom, 0xFFFFFF, 25, 1)

This is the part that I still don't get:

If UBound($coord2)>1 Then

MouseClick("right", $coord[0], $coord[1], 1, 3)

Sleep(1000)

MouseClick("right")

Sleep(1000)

ExitLoop

I don't know what Ubound does except it gives me the error that $coord2 is undefinded.

I just want this to search the first Area for a Blue pixel until it finds it or the time runes out, then restart the search. Then use the defined box around that Blue pixel to search for a White pixel until it finds it or the timer expires.

I'm sure this is really easy to someone who knows how... and I obviously don't.

Thanks for anymore help you all can provide!

Patrick

Share this post


Link to post
Share on other sites

Okey.. having no program experience is really holding me back here...  I'm sure I have all the pieces for what i am trying to do, but putting them together is really giving me a headache.

.

.

.

This is the part that I still don't get:

If UBound($coord2)>1 Then

MouseClick("right", $coord[0], $coord[1], 1, 3)

Sleep(1000)

MouseClick("right")

Sleep(1000)

ExitLoop

I don't know what Ubound does except it gives me the error that $coord2 is undefinded.

Patrick

<{POST_SNAPBACK}>

UBound() is used to find out how many elements are in an array, but only works if the variable is an array. In your case, when PixelSearch does not find the color, it returns the integer 1 (although the help file does not mention that), not an array.

Instead of using UBound, use IsArray... "If IsArray ($coord2) Then ... EndIf".

This does not address the looping and timing out issues. For the moment, I assume that's not part of the problem.


Phillip

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0