Sign in to follow this  
Followers 0
DustinBowers

Help with Loops

4 posts in this topic

Hi, I'm new to AutoIt programming. And havent programmed anything since Visual Basic4.0 was considered new lol.I made a loop to create multiple labels on a form, and it works great. once the script finishes placing the labels i made another loop to check for user clicks on the labels, i want the user to be able to click on the label, and when the label is clicked run the code inside the Case statement. so far ive tried many ways to run this code, it either constantly triggers the first labels code or doesnt recognize any mouseclick on any label at all. any suggestions?

Here is the code for the func im working with:

Func CalcCrop3()
    Sleep(5000)
    
    _ScreenCapture_Capture("Farm.jpg");Captures the screen view
    msgbox(0, 'Done', 'Screen Capture Complete, Press OK to continue.')

    GLOBAL $PicMain = GUICreate("FarmBot - [Calibration Mode]", 1024, 768, -3, -29); Creates window to place picture in
    GLOBAL $ImgForm = GUICtrlCreatePic("Farm.JPG", 0, 0, 1024, 768); places picture in new window

    GUISetState()   ;Mayneed to add: @SW_SHOW
    
    ;   GUICtrlSetState($PicMain, $GUI_FOCUS)
    ;=========THIS SECTION GETS THE 4 CORNERS OF YOUR FARM LAYOUT============== 
        MsgBox(0, "Crop Select", "Place curser over Top Crop and Press: [ENTER]")
        $GetCrop = MouseGetPos()
        Sleep(100)
INIWRITE("FarmBotBeta4.ini", "Calibrate", "FirstX", $GetCrop[0])
INIWRITE("FarmBotBeta4.ini", "Calibrate", "FirstY", $GetCrop[1])
        
        MsgBox(0, "Crop Select", "Place curser over Bottom Crop and Press: [ENTER]")
        $GetCrop = MouseGetPos()
        Sleep(100)
INIWRITE("FarmBotBeta4.ini", "Calibrate", "LastX", $GetCrop[0])
INIWRITE("FarmBotBeta4.ini", "Calibrate", "LastY", $GetCrop[1])
        
        MsgBox(0, "Crop Select", "Place curser over Left Crop and Press: [ENTER]")
        $GetCrop = MouseGetPos()
        Sleep(100)
INIWRITE("FarmBotBeta4.ini", "Calibrate", "LeftX", $GetCrop[0])
INIWRITE("FarmBotBeta4.ini", "Calibrate", "LeftY", $GetCrop[1])
        
        MsgBox(0, "Crop Select", "Place curser over Right Crop and Press: [ENTER]")
        $GetCrop = MouseGetPos()
        Sleep(100)
INIWRITE("FarmBotBeta4.ini", "Calibrate", "RightX", $GetCrop[0])
INIWRITE("FarmBotBeta4.ini", "Calibrate", "RightY", $GetCrop[1])
        Sleep(500)
    ;===================================================================================
    
    
    ;=============LOCAL VARIABLES LIST===================================================
    Local $FirstX = IniRead("FarmBotBeta4.ini", "Calibrate", "FirstX", "Error")
    Local $FirstY = IniRead("FarmBotBeta4.ini", "Calibrate", "FirstY", "Error")
    Local $LastX = IniRead("FarmBotBeta4.ini", "Calibrate", "LastX", "Error")
    Local $LastY = IniRead("FarmBotBeta4.ini", "Calibrate", "LastY", "Error")
    Local $LeftX = IniRead("FarmBotBeta4.ini", "Calibrate", "LeftX", "ERROR")
    Local $LeftY = IniRead("FarmBotBeta4.ini", "Calibrate", "LeftY", "ERROR")
    Local $RightX = IniRead("FarmBotBeta4.ini", "Calibrate", "RightX", "ERROR")
    Local $RightY = IniRead("FarmBotBeta4.ini", "Calibrate", "RightY", "ERROR")
    Local $1StepX = $RightX - $FirstX
    Local $1StepY = $RightY - $FirstY
    Local $2StepX = $1StepX /19
    Local $2StepY = $1StepY /19
    Local $3StepX = 25
    Local $3StepY = 12
    Local $ColWidth = Round($1StepX / 25) + 1 ;Should return a value of 20 on my current farm.
    INIWRITE("FarmBotBeta4.ini", "Calibrate", "ColWidth", $ColWidth)
    Local $GetCrop[2];Not sure if this variable def is redundent.. may not be needed
    Local $ColX = $FirstX
    Local $ColY = $FirstY
    Local $Counting = 0
    Local $CropNum = 1
    Local $Label1[401];Set to max num of fields available in farmville 24x24=576
    Local $CropCoords[2]
    Local $3BStepX = 25
    Local $3BStepY = -12
    Local $nMsg = 0
    ;=====================================================================================
    
While $Counting < $ColWidth 
    ;Do 
    Local $i = 0
    
        If $Counting = $ColWidth then ExitLoop
        While $i <= $ColWidth
    
                $TrueStepX = $i * $3StepX
                $TrueStepY = $i * $3StepY
            
                If $i = $ColWidth then EXITLOOP
                $Label1[$CropNum] = GUICtrlCreateLabel($CropNum, Round($ColX + $TrueStepX, 0), Round($ColY + $TrueStepY, 0), 6, 6)
                
                ;IF THIS TEST SCRIPT SECTION DOESNT WORK. USE OLD SECTION BELOW
                INIWRITE("Crops.ini", $CropNum, "XY", Round($ColX + $TrueStepX, 0) & "," & Round($ColY + $TrueStepY, 0))
                ;INIWRITE("Crops.ini", $CropNum, "Y", Round($ColY + $TrueStepY, 0))
                ;END NEW SECTION - BEGIN OLD SECTION
                
                $i = $i + 1
                $CropNum = $CropNum + 1 ; This counts total amount of crops
        
        WEnd
        
    $ColX = $ColX - Round($3BStepX, 0)
    $ColY = $ColY - Round($3BStepY, 0)
    $Counting = $Counting + 1

    ;Until $Counting > $ColWidth
Wend
    ;Msgbox(0, "TEST", "Made it out of loop")
    ;GUISetState($PicMain, $GUI_FOCUS)
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Label1[0]
            MsgBox(0,"", "You pushed the Button" & $Label1[0])
            GUICtrlSetBkColor($Label1[0], $GUI_BKCOLOR_TRANSPARENT)
            GUICtrlSetColor ( $Label1[0], 0xFF0000)
            Case $Label1[1]
            MsgBox(0,"", "You pushed the Button" & $Label1[1])
            GUICtrlSetBkColor($Label1[1], $GUI_BKCOLOR_TRANSPARENT)
            GUICtrlSetColor ( $Label1[1], 0x00ff00)
            Case $Label1[2]
            MsgBox(0,"", "You pushed the Button" & $Label1[2])
            GUICtrlSetBkColor($Label1[2], $GUI_BKCOLOR_TRANSPARENT)
            GUICtrlSetColor ( $Label1[2], 0x00ff00)
            Case $Label1[3]
            MsgBox(0,"", "You pushed the Button" & $Label1[3])
            GUICtrlSetBkColor($Label1[3], $GUI_BKCOLOR_TRANSPARENT)
            GUICtrlSetColor ( $Label1[3], 0x00ff00)
            Case $Label1[4]
            MsgBox(0,"", "You pushed the Button" & $Label1[4])
            GUICtrlSetBkColor($Label1[4], $GUI_BKCOLOR_TRANSPARENT)
            GUICtrlSetColor ( $Label1[4], 0x00ff00)
            Case $Label1[5]
            MsgBox(0,"", "You pushed the Button" & $Label1[5])
            GUICtrlSetBkColor($Label1[5], $GUI_BKCOLOR_TRANSPARENT)
            GUICtrlSetColor ( $Label1[5], 0x00ff00)
    EndSwitch
WEnd
        
    EndFunc

Share this post


Link to post
Share on other sites



I just added the $SS_NOTIFY tag to the label, still no change. currently the script places all the labels on the form then keeps selecting the first one on the list over and over. ive been toying with this section of code all day. with no success. i made a smaller code test version and it works great. ive decided to share the test version, i cant see why it doesnt work in my final project.

Test script here works,:

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
$i = 0
Local $Label1[400]
Local $Mouse[2]
$Form1 = GUICreate("Form1", 633, 447, 193, 125)
;GUISetBkColor($Form1, 0x000000)
GUISetState(@SW_SHOW)

While $i <= 5
If $i = 5 then exitloop
;Msgbox(0, "Click", " Click")
;$Mouse = MouseGetPos()

sleep(250)
$Label1[$i] = GUICtrlCreateLabel("X",$i * 10, 10, 12, 12)
;GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
;GUISetState(@SW_SHOW)

$i = $i + 1
Wend

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Label1[0]
            MsgBox(0,"", "You pushed the Button" & $Label1[0])
            GUICtrlSetBkColor($Label1[0], $GUI_BKCOLOR_TRANSPARENT)
            GUICtrlSetColor ( $Label1[0], 0xFF0000)
            Case $Label1[1]
            MsgBox(0,"", "You pushed the Button" & $Label1[1])
            GUICtrlSetBkColor($Label1[1], $GUI_BKCOLOR_TRANSPARENT)
            GUICtrlSetColor ( $Label1[1], 0x00ff00)
            Case $Label1[2]
            MsgBox(0,"", "You pushed the Button" & $Label1[2])
            GUICtrlSetBkColor($Label1[2], $GUI_BKCOLOR_TRANSPARENT)
            GUICtrlSetColor ( $Label1[2], 0x00ff00)
            Case $Label1[3]
            MsgBox(0,"", "You pushed the Button" & $Label1[3])
            GUICtrlSetBkColor($Label1[3], $GUI_BKCOLOR_TRANSPARENT)
            GUICtrlSetColor ( $Label1[3], 0x00ff00)
            Case $Label1[4]
            MsgBox(0,"", "You pushed the Button" & $Label1[4])
            GUICtrlSetBkColor($Label1[4], $GUI_BKCOLOR_TRANSPARENT)
            GUICtrlSetColor ( $Label1[4], 0x00ff00)
    EndSwitch
WEnd

Share this post


Link to post
Share on other sites

It looks like you're working on a bot here (Farmville or whatever else).

You should be aware about how bots are regarded here - just look at the closed threads.

Good luck working alone on that script.


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

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