Sign in to follow this  
Followers 0
adrian1386

Overstack error?

8 posts in this topic

Ok yes I know my script it probably crap but it does what I need and Iam not pretending to have good knowlege of any programing language so bear with me.

Basicaly the script runs for about an hour or two and than I get some sort of "to avoid overstack error" on my code. I think its on the target part. Anyway heres my code and how do I get around that.

WinActivate("program", "")

Sleep(3000)

Call("main")

Func main()

$health = PixelGetColor (80,98)

If $health = 44263 Then

Call("target")

Else

Sleep(10000)

Call("target")

EndIf

EndFunc

Func target()

Send("{TAB}")

$target = PixelGetColor (80,98)

If $target = 44263 Then

Call("combat")

Else

Send("{TAB}")

Call("combat")

EndIf

EndFunc

Func combat()

Send("7")

Sleep(3000)

Send("=")

Sleep(1000)

$i = 0

While $i <= 2

Send("4")

Sleep(2100)

Send("5")

Sleep(2100)

Send("6")

Sleep(2100)

Send("7")

Sleep(2100)

Send("8")

Sleep(2100)

$i = $i + 1

Wend

Call("main")

EndFunc

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

To use code tags.. Try highlighting your code and clicking the code tag button or use brackets [] with code and /code (/code represents end of code) in them.

I don't know why personally that you would get the overstack error, but I just put your script in one function.

WinActivate("program", "")
Sleep(3000)
main()
Func main()
    While 1
        $health = PixelGetColor (80,98)
        If $health = 44263 Then
            Send("{TAB}")
            $target = PixelGetColor (80,98)
            If $target = 44263 Then
                Send("7")
                Sleep(3000)
                Send("=")
                Sleep(1000)
                $i = 0
                While $i <= 2
                    Send("4")
                    Sleep(2100)
                    Send("5")
                    Sleep(2100)
                    Send("6")
                    Sleep(2100)
                    Send("7")
                    Sleep(2100)
                    Send("8")
                    Sleep(2100)
                    $i = $i + 1
                Wend
            Else
                Send("{TAB}")
                Send("7")
                Sleep(3000)
                Send("=")
                Sleep(1000)
                $i = 0
                While $i <= 2
                    Send("4")
                    Sleep(2100)
                    Send("5")
                    Sleep(2100)
                    Send("6")
                    Sleep(2100)
                    Send("7")
                    Sleep(2100)
                    Send("8")
                    Sleep(2100)
                    $i = $i + 1
                Wend
            EndIf
        Else
            Sleep(10000)
            Send("{TAB}")
            $target = PixelGetColor (80,98)
            If $target = 44263 Then
                Send("7")
                Sleep(3000)
                Send("=")
                Sleep(1000)
                $i = 0
                While $i <= 2
                    Send("4")
                    Sleep(2100)
                    Send("5")
                    Sleep(2100)
                    Send("6")
                    Sleep(2100)
                    Send("7")
                    Sleep(2100)
                    Send("8")
                    Sleep(2100)
                    $i = $i + 1
                Wend
            Else
                Send("{TAB}")
                Send("7")
                Sleep(3000)
                Send("=")
                Sleep(1000)
                $i = 0
                While $i <= 2
                    Send("4")
                    Sleep(2100)
                    Send("5")
                    Sleep(2100)
                    Send("6")
                    Sleep(2100)
                    Send("7")
                    Sleep(2100)
                    Send("8")
                    Sleep(2100)
                    $i = $i + 1
                Wend
            EndIf
        EndIf
    Sleep(10)
    WEnd
EndFunc  ;==>main

Edit: :P

Did the code tags wrong myself!!

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

This code should also do the same job:

WinActivate('Program')
Sleep(3000)

; Loop indefinitely
While 1
    If PixelGetColor(80, 98) <> 0x00ACE7 Then Sleep(10000)
; Target
    Send('{TAB}')
    If PixelGetColor(80, 98) <> 0x00ACE7 Then Send('{TAB}')
; Combat
    Send('7')
    Sleep(3000)
    Send('=')
    Sleep(1000)
    For $I = 1 To 3
        SendWithDelay(2100, '45678')
    Next
WEnd

Func SendWithDelay($Delay, $Keys)
    Local $Opt = Opt('SendKeyDelay', $Delay)
    Send($Keys)
    Opt('SendKeyDelay', $Opt)
EndFunc

Edit: As you were sending a sequence of keys with a specific delay between them, I coded a quick function called SendWithDelay() which does the same thing from one line of code. There's nothing at all wrong with the original approach though.

Edited by LxP

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Blah... My PM to you was too late :P, this is why I keep comming back to this forum, is because of people like LxP, that take the time with individual codes to help people out...

Edit: Quick question of my own...

Func SendWithDelay($Delay, $Keys)
    Local $Opt = Opt('SendKeyDelay', $Delay)
    Send($Keys)
    Opt('SendKeyDelay', $Opt)
EndFunc

$Opt = Opt('SendKeyDelay', $Delay)

Opt('SendKeyDelay', $Opt)

No matter what my test:

$Delay = 10
$Opt = Opt('SendKeyDelay', $Delay)
MsgBox(0, "", $Opt)
I get 5 as the value of $Opt... is that what you were after? Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

I'll discuss what was happening with the original code because this is brought up often:

It's common for people to restart a single function by calling it from within itself, or to loop through a set of functions by calling the next function from the end of the previous function. What's forgotten at this point is that AutoIt wants to return to the calling function after the called function ends, which never happens.

Ultimately, Func1() has called Func2() has called Func3() has called Func1() has called Func2() has called Func3() has called Func1() has called Func2() has called Func3() has called Func1()... and AutoIt packs it in before Windows cries.

It's absolutely vital to remember that functions are designed to return to their calling code after they complete. If you need some form of infinite loop then it's necessary to use a proper looping structure such as While..WEnd, which will loop 'while' some condition is true. While 1..WEnd gives you an indefinite loop without fears of a stack overflow.

Also, Call('SomeFunc') is not necessary -- SomeFunc() will do the job nicely.

P.S. Welcome to the forums!

Share this post


Link to post
Share on other sites

Blah... My PM to you was too late :P, this is why I keep comming back to this forum, is because of people like LxP, that take the time with individual codes to help people out...

Always like to hear appreciation... :">

Edit: Quick question of my own...

Func SendWithDelay($Delay, $Keys)
    Local $Opt = Opt('SendKeyDelay', $Delay)
    Send($Keys)
    Opt('SendKeyDelay', $Opt)
EndFunc

$Opt = Opt('SendKeyDelay', $Delay)

Opt('SendKeyDelay', $Opt)

No matter what my test:

$Delay = 10
$Opt = Opt('SendKeyDelay', $Delay)
MsgBox(0, "", $Opt)
I get 5 as the value of $Opt... is that what you were after?
Yes. $Opt contains the value of SendKeyDelay before the new Opt() overwrites it. By doing this, you can write functions that use their own Opt() settings without fear of breaking something in the main script.

$Opt = Opt('SendKeyDelay', 10)
MsgBox(0x40, 'SendKeyDelay', 'Current value is ' & Opt('SendKeyDelay') & @LF & 'Previous value was ' & $Opt)

Share this post


Link to post
Share on other sites

Always like to hear appreciation... :">

Yes. $Opt contains the value of SendKeyDelay before the new Opt() overwrites it. By doing this, you can write functions that use their own Opt() settings without fear of breaking something in the main script.

$Opt = Opt('SendKeyDelay', 10)
MsgBox(0x40, 'SendKeyDelay', 'Current value is ' & Opt('SendKeyDelay') & @LF & 'Previous value was ' & $Opt)
I'll be damned! :P I love learning something new, no matter how minor/major it is!!

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Thank you very much for the help. I'll take from this and learn. Really appreciate the time taken to help me. I've very minimal coding skill, infact this is the first time I'm picking up scripting in 2-3 years and back than I wasn't good to start with lol. Once again thanks.

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