Sign in to follow this  
Followers 0
Zenodice

Issues with PixelSearch

6 posts in this topic

#1 ·  Posted (edited)

So I've decided I wanted to write a relatively simple macro to help me raise my fishing skill in WoW (all that clicking is tedious and hurts my hand after awhile).

I've got a decent start on it but there are a few things that are still eluding me, first of all in the Cast() function when it goes to do the mousemove I get an error approx half the time which states " ==> Subscript used with non-Array variable.", now it may just be me being tired at 3am but I'm wondering what I'm missing that could cause a simple mousemove to break the script.

The other half of the time, it seems to locate the color I've selected and claims to finish the rest of the script but in actuality seems to never move the mouse or do anything at all.

Now just to clarify, here's my thought process of how things should be going:

*user selects search area

*user selects color

*script start

*script searches search area for color

*once color is found, move mouse to hotspot

*check hotspot until color is no longer found

*DING fish is caught, right-click at hotspot and repeat from script start

As opposed to what actually happens which is either

*user selects search area

*user selects color

*script start

*script searches search area for color

*once color is found, attempt to move mouse to hotspot, throw error & crash

Or

*user selects search area

*user selects color

*script start

*script searches search area for color

*once color is found, attempt to move mouse to hotspot .... instead do nothing

*thinks fish is caught, does nothing and repeat from script start

I'm sure it's probably something minor that I'm just blind to at the moment but I cant stare at this code any longer as I have to get up in 6 hours for a job interview and figured I'd get some more educated eyes to point out whatever errors I'm making here.

Thanks in advance for any help anyone can provide or guidance in the proper direction, please excuse the sloppy and noobish code. :D

;DO NOT TOUCH - ALTERING THESE WILL BREAK THE MACRO
#include <WINAPI.au3>
#Include <Misc.au3>
Global $wow = 'World of Warcraft'
Global $searchL, $searchT, $searchR, $searchB, $color

;FishKey - Change this to the key you use to fish
Global $FishKey = '{HOME}'

;MAIN MACRO
WinActivate("World of Warcraft") ; activate window
ToolTip("Opening WoW window...", 0, 0); displays tooltip in top left corner
WinWaitActive("World of Warcraft") ; wait untill the window is active

While 1
WinWaitActive("World of Warcraft")
ToolTip("Executing script...", 0, 0) ; displays tooltip in top left corner
Sleep (2000)
    Prep()
Wend

;Prep functions - sets up macro
Func Prep()
    ToolTip("Setting up coordinates, prepare for further instructions...", 0, 0) ; displays tooltip in top left corner
    Sleep (2000)
    
    ;Prompts user to select the upper left of the search area
    ToolTip('Click in the top left corner of the search area',0,0,"",2)
    While 1
        If WinActive("World of Warcraft") = 0 Then WinActivate("World of Warcraft") ; Make sure WoW stays active while user is selecting position
        If _IsPressed("01") Then ExitLoop ; Exit loop when user left clicks
    WEnd
    $mouse = MouseGetPos()
    $searchL = $mouse[0]
    $searchT = $mouse[1]
    Sleep(1000)

    ;Prompts user to select the lower right of the search area
    ToolTip('Click in the bottom right corner of the search area',0,0,"",2)
    While 1
        If WinActive("World of Warcraft") = 0 Then WinActivate("World of Warcraft") ; Make sure Wow stays active while user is selecting position
        If _IsPressed("01") Then ExitLoop ; Exit loop when user left clicks
    WEnd
    $mouse = MouseGetPos()
    $searchR = $mouse[0]
    $searchB = $mouse[1]
    Sleep(3000)
        
    Send($FishKey)
    While 1
        If WinActive("World of Warcraft") = 0 Then WinActivate("World of Warcraft") ; Make sure Wow stays active while user is selecting color
        $mouse = MouseGetPos()
        $color = PixelGetColor($mouse[0],$mouse[1])
        ToolTip("Find the red part of the feather on the bobber and click it, if fishing timer runs out press your fishing key and try again.",0,0)  ; displays tooltip in top left corner
        If _IsPressed("01") Then ExitLoop; Exit loop when user left clicks
    WEnd
    Msgbox(0,"Status", "Bobber color: "&$color) ;Debug, DONT TOUCH
    ToolTip("Starting macro", 0, 0) ; displays tooltip in top left corner
    Sleep (2000)
    Cast()
EndFunc


;Cast Function
func Cast()
    ToolTip("Casting...", 0, 0) ; displays tooltip in top left corner
    Sleep(1000)
    Send($FishKey)
    ToolTip("Searching for bobber...", 0, 0) ; displays tooltip in top left corner
    Sleep (500)
    Global $current = timerinit() ; Set a timeout for finding splash
    $bobber = PixelSearch($searchL,$searchT,$searchR,$searchB, $color,10) ; Look for user selected color
    If TimerDiff($current) > 10000 Then ;If the bobber is not seen in 10 sec. Then cast again
        Cast()
    EndIf
    sleep (3000)
    MouseMove($bobber[0], $bobber[1]) ; Move the mouse to the bobber
    ToolTip("Found bobber, waiting for fish to be hooked...", 0, 0) ; displays tooltip in top left corner
    Sleep (500)
    
while 1
    Global $current = timerinit() ; Set a timeout for finding splash
    $splash = PixelSearch($bobber[0]-10,$bobber[1]-10,$bobber[0]+10,$bobber[1]+10, $color, 10) ; Search a tiny 20x20 square for the bobber color
    If @error = 1 Then ExitLoop ; When the color isn't found, the bobber has bobbed
    Sleep(100)
    if Round(timerdiff($current)/1000,0) >= 30 Then;If the splash is not seen in 30 sec. Then cast again
        Cast()
    EndIf
wend

    ;the bobber color has changed (a fish is hooked), loot bobber and repeat.
    ToolTip("Splash detected, looting fish...", 0, 0) ; displays tooltip in top left corner
    Sleep(Random(75,175))
    MouseClick("Right", $bobber[0], $bobber[1], 1, 0) ; Even if the user moves the mouse, this instantly moves it to the bobber and right-clicks
    Sleep(3000)
    ToolTip("Recasting...", 0, 0) ; displays tooltip in top left corner
    Sleep (2500)
    Cast()
EndFunc
Edited by Zenodice

Share this post


Link to post
Share on other sites



It would have been easier if you wrote down the line number on which it crashes, that helps a lot when searching.

Anyway, this can potentially go wrong because you never check for @error:

$bobber = PixelSearch($searchL,$searchT,$searchR,$searchB, $color,10) ; Look for user selected color in a large area in the center of the screen
; Some stuff
MouseMove($bobber[0], $bobber[1]) ; Move the mouse to the bobber (so the user knows what this script is looking at, and hopefully doesn't move the mouse)

Share this post


Link to post
Share on other sites

It would have been easier if you wrote down the line number on which it crashes, that helps a lot when searching.

Anyway, this can potentially go wrong because you never check for @error:

$bobber = PixelSearch($searchL,$searchT,$searchR,$searchB, $color,10) ; Look for user selected color in a large area in the center of the screen
; Some stuff
MouseMove($bobber[0], $bobber[1]) ; Move the mouse to the bobber (so the user knows what this script is looking at, and hopefully doesn't move the mouse)

K, I added the following, same issues.

$bobber = PixelSearch($searchL,$searchT,$searchR,$searchB, $color,10) ; Look for user selected color
    If @error = 1 Then Cast() 
    If TimerDiff($current) > 10000 Then ;If the bobber is not seen in 10 sec. Then cast again
        Cast()
    EndIf
    sleep (3000)
    MouseMove($bobber[0], $bobber[1]) ; Move the mouse to the bobber

Share this post


Link to post
Share on other sites

Let's focus on one problem at a time, and let's start with the one where we know specifically what's going wrong: The array subscript exceeded error.

I asked you for a line number, so post one.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Let's focus on one problem at a time, and let's start with the one where we know specifically what's going wrong: The array subscript exceeded error.

I asked you for a line number, so post one.

I actually fixed it, it seems that lack of error trapping was one of the issues and the other was too much variation in the color for the pixel search to find the desired target.

Thanks for your help Manadar.

Edited by Zenodice

Share this post


Link to post
Share on other sites

I actually fixed it, it seems that lack of error trapping was one of the issues and the other was too much variation in the color for the pixel search to find the desired target.

Thanks for your help Manadar.

As I had guessed.. : )

I've built my fair share of fishing bots and other game bots to know about what can typically go wrong.

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