Jump to content

Recommended Posts

Im having trouble here is my code

$Plant = IniRead("settings.ini", "Main", "Plant", "Error Reading INI")
$Harvest = IniRead("settings.ini", "Main", "Harvest", "Error Reading INI")

AutoItSetOption("MouseCoordMode", 0)
WinActivate("Window")
Sleep(4000)
Global $slot1
Global $slot2
Global $slot3
Global $p
Global $h
$p = 0
$h = 0

;section1
If WinExists("Window") Then
Do
$slot1 = MouseMove(25,66)
MouseClick("left")
MouseClick("left")
Sleep(1000)
MouseMove(461,318)
Sleep(1000)
MouseClick("left")
Sleep(1000)
$slot3 = MouseMove(85,68)
Sleep(1000)
MouseClick("left")
MouseClick("left")
Sleep(1000)
MouseMove(461,318)
MouseClick("left")
Sleep(2000)
Send("{UP}")
$p = $p + 1
Until $p = $plant

Else

;section 2
if $p <= $plant Then
Do
Sleep(900)
$slot3 = MouseMove(56,65)
MouseClick("left")
MouseClick("left")
Sleep(1000)
MouseMove(461,318)
Sleep(1000)
MouseClick("left")
Sleep(3000)
Send("{DOWN}")
$h = $h + 1
Until $h = $Harvest
EndIf

If NOT WinExists("Window") Then
MsgBox(16, "Window Is Not Present In Memory")
EndIf

Ok now my problem is that it does the first section of code but when it gets to the 2nd part (else) it does not do it and the program closes.

I was hoping to make it do the 1st set there and then move on to the 2nd section but only the ammount of times that is put into the INI.

I am very lost this is for personal use only, for a game yes but only being made to help me understand things better i hope im not breaking any rules here B)

Thanks in advance :whistle:

Link to post
Share on other sites

Basically your structure (after adding the missing EndIf pointed out by Valik) is as follows:

$p = 0
$h = 0
;section 1
If WinExists("Window") Then
  Do
   ; Code that plants stuff
    $p = $p + 1
  Until $p = $plant

Else

 ;section 2
  if $p <= $plant Then
    Do
     ; Code that harvests stuff
      $h = $h + 1
    Until $h = $Harvest
  EndIf
EndIf

I gather that what you want to do is plant some stuff $plant times, and then harvest stuff $harvest times. To do this you first need to remove the Else statement. The line

if $p <= $plant Then

is redundant, because it only gets there when $p is equal to $plant. Therefore the test will always be true. Therefore that line can be removed as well. Thus the code becomes

$p = 0
$h = 0
;section 1
If WinExists("Window") Then
  Do
   ; Code that plants stuff
    $p = $p + 1
  Until $p = $plant

 ;section 2
  Do
   ; Code that harvests stuff
    $h = $h + 1
  Until $h = $Harvest
EndIf

HTH

GrahamS

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...