Sign in to follow this  
Followers 0
adroitful

Most efficient way to code this?

13 posts in this topic

Well, my program works great, but it seems to get an error after a while saying it's using too many resources and it needs to be shut down to prevent an overflow. My question is what is the cause of this error and what is the most efficent way to code this? It just seems like there would be a better way. Thanks for any input

func pickit()
        ;checks to see if we're still logged in
            $isopen=pixelgetcolor(450,148)
if $isopen = 0x001B69 then call("login")
            $x1 = 0
            $y1 = 0
        ;Checks health status and then picks any good items up
            $health = pixelgetcolor(320,58)
            if $health = 0xFFFFFF then sleep(30000)
                    $blegendary = _ImageSearch("blegendary.bmp",0,$x1,$y1,0)
if $blegendary=1 Then mouseclick("left",$x1,$y1,6)
    sleep(200)
    $rlegendary = _ImageSearch("rlegendary.bmp",0,$x1,$y1,0)
if $rlegendary=1 Then mouseclick("left",$x1,$y1,6)
    sleep(200)
    $bgodly = _ImageSearch("bgodly.bmp",0,$x1,$y1,0)
if $bgodly=1 Then mouseclick("left",$x1,$y1,6)
    sleep(200)
    $rgodly = _ImageSearch("rgodly.bmp",0,$x1,$y1,0)
if $rgodly=1 Then mouseclick("left",$x1,$y1,6)
    sleep(200)
    $bepic = _ImageSearch("bepic.bmp",0,$x1,$y1,0)
if $bepic=1 Then mouseclick("left",$x1,$y1,6)
    sleep(200)
    $repic = _ImageSearch("repic.bmp",0,$x1,$y1,0)
if $repic=1 Then mouseclick("left",$x1,$y1,6)
    sleep(200)
    $barcane = _ImageSearch("$barcane.bmp",0,$x1,$y1,0)
if $barcane=1 Then mouseclick("left",$x1,$y1,6)
    sleep(200)
    sleep(200)
    $rarcane = _ImageSearch("$rarcane.bmp",0,$x1,$y1,0)
if $rarcane=1 Then mouseclick("left",$x1,$y1,6)
    sleep(200)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

In the code you have posted, you haven't closed any of the If statements or the Function itself. Also, where does _ImageSearch() come from and what is it doing?

I seriously hope you have more code than this because the code you have posted can't even be run by itself. We could help you better if you post it all at once, or at least the full functions pickit() and _ImageSearch().

Yea, I have alot more code. I'll post the whole thing. Imagesearch scans the screen for an image and if it's there, it returns 1 if not, 0. As far as the if statements go, they seem to work just fine. Why would I have to close the if statements?

Heres all of my code:

#include <ImageSearch.au3>
run("c:\browser.exe","")
sleep(3000)
$isopen=pixelgetcolor(450,148)
if $isopen = 0x001B69 then call("login")
call("login")
    func login()
        mouseclick("left",574,383)
        send("{bs} {bs}{bs} {bs}{bs} {bs}{bs} {bs}{bs} {bs}{bs} {bs}{bs} {bs}{bs} {bs}{bs} {bs} {bs} {bs}{bs} {bs}{bs} {bs}{bs} {bs}{bs} {bs}")
        sleep(2000)
        send("username)
        sleep(100)
        send("{tab}")
        sleep(100)
        send("password")
        sleep(100)
        send("{tab}")
;gold password
;send("goldpass")
        send("{tab}")
        sleep(100)
        send("{enter}")
        sleep(2000)
        $charsel = pixelgetcolor(829,493)
        if $charsel = 0x777777 then call("charselect")
        if $charsel <  0x777777 then msgbox(0x0,"Error","Couldnt login")
        if $charsel >  0x777777 then msgbox(0x0,"Error","Couldnt login")
            
    endfunc
    
    func charselect()
;selects character and goes to the arena
        mouseclick("primary",238,61,2)
        call("attack1")
    endfunc
    
    func attack1()
;checks to see if we're still logged in
        $isopen=pixelgetcolor(450,148)
if $isopen = 0x001B69 then call("login")
;goes to the arena
        sleep(2000)
        mouseclick("left",614,198)
        sleep(1000)

;select what lvl monster to spawn
;mouseclick("left",541,232)
;sleep(100)
;send("{bs}{bs}")
;sleep(100)
;send("2")
;sleep(100)
        mouseclick("left",587,147)
        sleep(1000)
        call("attack")
    endfunc
    
    func attack()
;checks to see if we're still logged In
        $isopen=pixelgetcolor(450,148)
if $isopen = 0x001B69 then call("login")
;attacks the monster
        mouseclick("left",499,312)
        mouseclick("left",501,318)
        mouseclick("left",482,329)
;checks if life percent is below a certain amount       
        $chicken = pixelgetcolor(167,58)
        if $chicken = 0xB90B0B then call("chicken")
        $mondead=pixelgetcolor(126,275)
        if $mondead=0xFFFFFF then call("attack")
    ;checks if monster is dead or not
        if $mondead=0x525252 then call("pickit")
        EndFunc
        
        func pickit()
    ;checks to see if we're still logged in
            $isopen=pixelgetcolor(450,148)
if $isopen = 0x001B69 then call("login")
            $x1 = 0
            $y1 = 0
    ;Checks health status and then picks any good items up
            $health = pixelgetcolor(320,58)
            if $health = 0xFFFFFF then sleep(30000)
                    $blegendary = _ImageSearch("blegendary.bmp",0,$x1,$y1,0)
if $blegendary=1 Then mouseclick("left",$x1,$y1,6)
    sleep(200)
    $rlegendary = _ImageSearch("rlegendary.bmp",0,$x1,$y1,0)
if $rlegendary=1 Then mouseclick("left",$x1,$y1,6)
    sleep(200)
    $bgodly = _ImageSearch("bgodly.bmp",0,$x1,$y1,0)
if $bgodly=1 Then mouseclick("left",$x1,$y1,6)
    sleep(200)
    $rgodly = _ImageSearch("rgodly.bmp",0,$x1,$y1,0)
if $rgodly=1 Then mouseclick("left",$x1,$y1,6)
    sleep(200)
    $bepic = _ImageSearch("bepic.bmp",0,$x1,$y1,0)
if $bepic=1 Then mouseclick("left",$x1,$y1,6)
    sleep(200)
    $repic = _ImageSearch("repic.bmp",0,$x1,$y1,0)
if $repic=1 Then mouseclick("left",$x1,$y1,6)
    sleep(200)
    $barcane = _ImageSearch("$barcane.bmp",0,$x1,$y1,0)
if $barcane=1 Then mouseclick("left",$x1,$y1,6)
    sleep(200)
    sleep(200)
    $rarcane = _ImageSearch("$rarcane.bmp",0,$x1,$y1,0)
if $rarcane=1 Then mouseclick("left",$x1,$y1,6)
    sleep(200)
    
;$bmagical = _ImageSearch("bmagical.bmp",0,$x1,$y1,0)
;if $bmagical=1 Then mouseclick("left",$x1,$y1,6)
;$rmagical = _ImageSearch("$rmagical.bmp",0,$x1,$y1,0)
;if $rmagical=1 Then mouseclick("left",$x1,$y1,6)
    
            call("picked")
        EndFunc
        func picked()
            mouseclick("left",176,268)
            sleep(100)
            call("attack")
        EndFunc
        
        func chicken()
    ;chicken out
        mouseclick("left",813,270)
        sleep(60000)
;enter back in
        call("attack1")
        endfunc
Edited by adroitful

Share this post


Link to post
Share on other sites

One line If..Then doesn't require EndIf, only multiple lines if statement. This ImageSearch library is using an external dll (probably made by the author) so it can be possible there is a memory leak problem in the dll, or not.

Share this post


Link to post
Share on other sites

One line If..Then doesn't require EndIf, only multiple lines if statement. This ImageSearch library is using an external dll (probably made by the author) so it can be possible there is a memory leak problem in the dll, or not.

I've had the memory problem before. It seems to do this when the code is constantly executed. I don't remember how I was told to fix it tho. I'll try and get it to come back up so I can screenshot it, but it takes a few hours. Also, I didn't think I had to have an endif statement for 1 line if's lol. I'm asking if theres a more efficient way to code all of those if... then statements?

Share this post


Link to post
Share on other sites

Probably yes, and you'll need to work on your logic because it's playing a great part in writing code. :D

For example:

if $charsel = 0x777777 then call("charselect")
if $charsel <  0x777777 then msgbox(0x0,"Error","Couldnt login")
if $charsel >  0x777777 then msgbox(0x0,"Error","Couldnt login")

Do you realize that if $charsel = 0x777777 then it's pointless to check if it's lesser or greater than 0x777777?

You could use If...ElseIf..EndIf or in a case of greater alternatives, it's better to use Select or Switch conditional structures.

Share this post


Link to post
Share on other sites

Probably yes, and you'll need to work on your logic because it's playing a great part in writing code. :D

For example:

if $charsel = 0x777777 then call("charselect")
if $charsel <  0x777777 then msgbox(0x0,"Error","Couldnt login")
if $charsel >  0x777777 then msgbox(0x0,"Error","Couldnt login")

Do you realize that if $charsel = 0x777777 then it's pointless to check if it's lesser or greater than 0x777777?

You could use If...ElseIf..EndIf or in a case of greater alternatives, it's better to use Select or Switch conditional structures.

I did that because I don't know the is not equal to argument :D . And i'll look into select... switch and see if I can't figure it out thanks. Does anyone know why i'm getting the memory problem?

Share this post


Link to post
Share on other sites

For "not equal to" you can use <>

Or you can do it with only one expression like :

If $charsel = 0x777777 then

call("charselect")

Else

msgbox(0,"Error","Couldnt login")

EndIf

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

you could replace this:

CODE

$blegendary = _ImageSearch("blegendary.bmp",0,$x1,$y1,0)

if $blegendary=1 Then mouseclick("left",$x1,$y1,6)

sleep(200)

$rlegendary = _ImageSearch("rlegendary.bmp",0,$x1,$y1,0)

if $rlegendary=1 Then mouseclick("left",$x1,$y1,6)

sleep(200)

$bgodly = _ImageSearch("bgodly.bmp",0,$x1,$y1,0)

if $bgodly=1 Then mouseclick("left",$x1,$y1,6)

sleep(200)

$rgodly = _ImageSearch("rgodly.bmp",0,$x1,$y1,0)

if $rgodly=1 Then mouseclick("left",$x1,$y1,6)

sleep(200)

$bepic = _ImageSearch("bepic.bmp",0,$x1,$y1,0)

if $bepic=1 Then mouseclick("left",$x1,$y1,6)

sleep(200)

$repic = _ImageSearch("repic.bmp",0,$x1,$y1,0)

if $repic=1 Then mouseclick("left",$x1,$y1,6)

sleep(200)

$barcane = _ImageSearch("$barcane.bmp",0,$x1,$y1,0)

if $barcane=1 Then mouseclick("left",$x1,$y1,6)

sleep(200)

sleep(200)

$rarcane = _ImageSearch("$rarcane.bmp",0,$x1,$y1,0)

if $rarcane=1 Then mouseclick("left",$x1,$y1,6)

sleep(200)

;$bmagical = _ImageSearch("bmagical.bmp",0,$x1,$y1,0)

;if $bmagical=1 Then mouseclick("left",$x1,$y1,6)

;$rmagical = _ImageSearch("$rmagical.bmp",0,$x1,$y1,0)

;if $rmagical=1 Then mouseclick("left",$x1,$y1,6)

with this:

Dim $Images[11] = ["blegendary.bmp", "rlegendary.bmp", "bgodly.bmp", "rgodly.bmp", "bepic.bmp", "repic.bmp", _
                   "repic.bmp", "barcane.bmp", "rarcane.bmp", "bmagical.bmp", "rmagical.bmp"]

For $i = 0 To UBound($Images) -1
    If _ImageSearch($Images[$i], 0, $x1, $1, 0) = 1 Then
        MouseClick("left",$x1,$y1,6)
    EndIf
Next

I also noticed that there were some "$" in your images name (like "$barcane.bmp") so I removed it

Edited by oMBRa

Share this post


Link to post
Share on other sites

try use controlclick , then you dont have to search for a field where to enter a username or password etc

Share this post


Link to post
Share on other sites

Wow thank you very much, this is excatly why I came here. I need to figure out these little tricks. Also, the memory error i'm getting says:

"Error: Recursion level has been exceeded - AutoIt will quit to prevent stack overflow. Any ideas?

Share this post


Link to post
Share on other sites

Wow thank you very much, this is excatly why I came here. I need to figure out these little tricks. Also, the memory error i'm getting says:

"Error: Recursion level has been exceeded - AutoIt will quit to prevent stack overflow. Any ideas?

That is because you are calling functions within functions... Try this

change...

call("attack")
    endfuncoÝ÷ Ù:ºÚ"µÍ]]XÚÊ
B[[

Change all of them.

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

That is because you are calling functions within functions... Try this

change...

call("attack")
    endfuncƒoÝŠ÷ Ù:ºÚ"µÍˆ™]›ˆ]XÚÊ
Bˆ[™[˜

Change all of them.

8)

Tyvm. n/m I figured it out. Thanks for all of the help guys Edited by adroitful

Share this post


Link to post
Share on other sites

Tyvm. Any ideas why i'm gettin a variable being used without being declared error in the following?

Yea "$x1, $y1," neither are not given a value in that snipit of code you gave

8)


NEWHeader1.png

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