Sign in to follow this  
Followers 0
BotTr

Simple But Stuck

7 posts in this topic

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:

Share this post


Link to post
Share on other sites



You appear to be missing an EndIf after:

Until $h = $Harvest

EndIf

EndIf <--- Put an EndIf here.

Share this post


Link to post
Share on other sites

The exe is still closing after the 1st section.

If i want it to do the 2nd section after the 1st am i suppose to use something besides Else??

Share this post


Link to post
Share on other sites

Oh, yes. I didn't see that that is what you wanted. If statements work like this:

If <condition evaluates to true> Then

; Do Stuff

Else ; This means the condition evaluated in the If statement was false

; Do other stuff

EndIf

Share this post


Link to post
Share on other sites

Yea thats what im stuck on because if i eliminate the Else it does the same thing over n over lol im sure this is simple again i am probably overlooking something.

:whistle:B)

Share this post


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

Share this post


Link to post
Share on other sites

i decided to use functions but this GrahamS youe method works great i appreciate all the help from you guys thanks :whistle:

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