Jump to content

Different Do Until


 Share

Recommended Posts

Ok maybe its something bigger than whet I'm seeing in my do until loop. I'm posting the whole script that I'm using. Its for a little game that my wife and I play at home against each other. When it gets to the Do...Until loop it just hangs for some reason. Any suggestions?

$FullStamina = PixelSearch(185, 287, 195, 295, 0x86671A, 20);stamina bar is full

While 1

Requip();re equips weapon after it breaks

send("u")

sleep(200)

LowHealth();life bar gets low

WepCheck();makes sure weapon is un shiethed

WEnd

Func LowHealth()

$coord = Pixelsearch(1728, 43, 1738, 52, 0x741A1A, 1) ;

If @error Then

sleep(1000)

send("o");shieth

sleep(3000)

send("b");toggle rest

sleep(1000)

send("u");trigger rest

Do

sleep(1000)

Until $FullStamina = 1

send("{SPACE}");stand up

sleep(4000)

send("{F9}");sends a command to my other computer

sleep(2000)

send("o");unshieth

sleep(1000)

EndIf

EndFunc

Func Requip()

$coord = PixelSearch(1519, 773, 1537, 798, 0x89635F, 20) ;

If @error Then;

Sleep(1000)

Send("g");my 0 slot on my hotbar where i have my polearm

Sleep(3000)

Send("o");unshieth

Sleep(1000)

EndIf

EndFunc ;==>_WeaponCheck

Func WepCheck()

$green = PixelSearch(15, 433, 39, 458, 0x137800, 20)

If @error Then

send("o")

sleep(500)

EndIf

EndFunc

Link to comment
Share on other sites

Do
  sleep(1000)
Until $FullStamina = 1

This will call sleep(1000) until $FullStamina is '1'.

But where between Do and Until $FullStamina is changing? Right: nowhere! So when you go into the loop with $FullStamina is '1', it still will be '1' for the rest of the programs life. That is, why you never will leave the Loop (at your prog hangs).

You have to set $FullStamina within your loop to see if it is '1' or not:

Do
  sleep(1000)
  $FullStamina = PixelSearch(185, 287, 195, 295, 0x86671A, 20)
Until $FullStamina = 1

A-Jay

Edited by ajag

Rule #1: Always do a backup         Rule #2: Always do a backup (backup of rule #1)

Link to comment
Share on other sites

Sooo...

Do
$FullStamina = PixelSearch(185, 287, 195, 295, 0xCCA028, 1)
If IsArray($FullStamina) Then $FullStamina[2] = 1
Sleep(1000)
Until $FullStamina[2] = 1

Didn't work? (http://www.autoitscript.com/forum/index.php?showtopic=107175)

You can also write it like:

While 1
Sleep(1000)
$FullStamina = PixelSearch(185, 287, 195, 295, 0xCCA028, 1)
If Not @error Then ExitLoop
WEnd
Edited by jebus495
Link to comment
Share on other sites

Im trying the first suggestion becasue as you said ive never seen it that way so im trying to learn something new here. It gives me an error for line 41 saying

Until $FullStamina[2] = 1

Until $FullStamina^ ERROR

Error Subscript used with non-Array variable

While 1

Requip();re equips weapon after it breaks

send("u")

sleep(200)

LowHealth();life bar gets low

WepCheck();makes sure weapon is un shiethed

WEnd

Func LowHealth()

$coord = Pixelsearch(1728, 43, 1738, 52, 0x741A1A, 1) ;

If @error Then

sleep(1000)

send("o");shieth

sleep(3000)

send("b");toggle rest

sleep(1000)

send("u");trigger rest

Do

$FullStamina = PixelSearch(185, 287, 195, 295, 0x86671A, 20);stamina bar is full

If IsArray($FullStamina) Then $FullStamina[2] = 1

sleep(1000)

Until $FullStamina[2] = 1

send("{SPACE}");stand up

sleep(4000)

send("{F9}");sends a command to my other computer

sleep(2000)

send("o");unshieth

sleep(1000)

EndIf

EndFunc

Func Requip()

$coord = PixelSearch(1519, 773, 1537, 798, 0x89635F, 20) ;

If @error Then;

Sleep(1000)

Send("g");my 0 slot on my hotbar where i have my polearm

Sleep(3000)

Send("o");unshieth

Sleep(1000)

EndIf

EndFunc ;==>_WeaponCheck

Func WepCheck()

$green = PixelSearch(15, 433, 39, 458, 0x137800, 20)

If @error Then

send("o")

sleep(500)

EndIf

EndFunc

Link to comment
Share on other sites

I used your second option and it did work! Thank you very much for your help. I am still interested in the first option just becasue i love learning new tricks. Im going to read up on IsArray and the rest of it. Any ideas on why the error came about though?

Link to comment
Share on other sites

Ah yes. I just made that kind of randomly. AutoIt tags have no error checking. XD

Declare: $IsFull somewhere in your script. Preferably at the top.

Do
$FullStamina = PixelSearch(185, 287, 195, 295, 0x86671A, 20);stamina bar is full
If IsArray($FullStamina) Then $IsFull = 1
sleep(1000)
Until $IsFull = 1
$IsFull = 0 ;reset the value so that it doesn't just skip past the loop the second time around.

The error occurred because $FullStamina isn't an array until the PixelSearch finds the color. So the loop reaches the end and looks at $FullStamina[2] and goes HEY! that's not an array at all and proceeds to fail.

Edited by jebus495
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...