Jump to content

Having some trouble with booleans and PixelSearch


Recommended Posts

lack of $ before the variable name

; scans for green values, if green, it holds the LMB
; scans for red values, if red, it lets go, if it doesn't see red, it holds the LMB
; scans for indicator, if indicator, it stops fishing
;greenINDI = green ! redINDI = red ! INDI = dock

HotKeySet("{ESC}", "Terminate")
HotKeySet("!g", "startBot");

Global $greenINDI[3]
Global $redINDI[3]
Global $INDI
Global $seenGreen

MsgBox(0, "BOT START", "Bot has started and is idling.")

Func Terminate()
    Exit 1
EndFunc   ;==>Terminate

Func startBot()

    ;clicks to start charge --done
    ;waits 20-500 ms --done
    ;clicks --done


    MsgBox(0, "fishEZ", "Gone fishing!") ;;indicates bot has started

    Local $rng

    $rng = Random(50, 200, 0)

    MouseClick('Left') ;single click to start charge bar going up and down

    Sleep($rng) ;sleep allows the charge bar to rise

    MouseClick('Left') ;stops the charge from moving and throws the hook into the water

    
    ;Call("GreenINDI") ; puts colors into greenINDI
    GreenINDI()
    ;Call("RedINDI")  ; puts colors into redINDI
    RedINDI()
    
    Local $screenCoords = WinGetPos("[ACTIVE]")

    $seenGreen = False

    While 1
        While $seenGreen ;this while should search for green

            $rng = Random(0, 2, 0)
            ;searches for green
            $point = PixelSearch(($screenCoords[2] * .25), ($screenCoords[3] * .25), ($screenCoords[2] * .75), ($screenCoords[3] * .75), $greenINDI[$rng])
            If IsArray($point) Then
                MouseDown('Left')
                ;stop searching for green
                $seenGreen = True
            EndIf
            Sleep(50)
        WEnd

        While $seenGreen = True ;this while should search for red, and should only search when it has seen green
            $rng = Random(0, 2, 0)
            ;searches for red
            $point = PixelSearch(($screenCoords[2] * .25), ($screenCoords[3] * .25), ($screenCoords[2] * .75), ($screenCoords[3] * .75), $redINDI[$rng])
            If IsArray($point) Then
                MouseUp('Left')
            EndIf
            MouseDown('Left') ;with any luck, this should hold LMB down if at any time red was seen
            Sleep(50)
        WEnd

    WEnd

EndFunc   ;==>startBot

Func GreenINDI() ;assigns 3 green colors to greenINDI
    $greenINDI[0] = "0x1ED72C"
    $greenINDI[1] = "0x1BCD1F"
    $greenINDI[2] = "0x1FDA26"
EndFunc   ;==>GreenINDI

Func RedINDI() ;assigns 3 red colors to redINDI
    $redINDI[0] = "0xF40001"
    $redINDI[1] = "0xF30101"
    $redINDI[2] = "0xEE0101"
EndFunc   ;==>RedINDI

While 1
    Sleep(250)
WEnd

 

Edited by Trong

Regards,
 

Link to comment
Share on other sites

 if it is not variable, it is a function, but I do not see that function is declared in the script

data can not be assigned to the function
line 47 : it was not way call the function
....

 

 

You should read how to use variables and functions here:

https://www.autoitscript.com/autoit3/docs/intro/lang_variables.htm

https://www.autoitscript.com/autoit3/docs/intro/lang_functions.htm

https://www.autoitscript.com/wiki/Best_coding_practices

Edited by Trong

Regards,
 

Link to comment
Share on other sites

I see what you are talking about. My brain was deleting the $s you put in your post. I get it now. I was missing the $s for pretty much all of my errors except for line 47.

 

I am still confused about line 47, how do I make it say while seenGreen = true even though it is false? From my understanding, put a ! in front means the opposite, but this does not seem to work in Autoit.

Link to comment
Share on other sites

https://www.autoitscript.com/autoit3/docs/intro/lang_operators.htm

 

While $expression      ;$expression=True then True  - $expression=False then False
While Not $expression ;$expression=False then True - $expression=False then True
While $seenGreen = True ;True=1 $seenGreen=True then True $seenGreen=False then False
While $seenGreen = False ;False=0 $seenGreen=False then True $seenGreen=False then True

 

Edited by Trong

Regards,
 

Link to comment
Share on other sites

  • Moderators

robotmad50,

Which game are you automating?

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...