Problem with stack overflow in my bot

5 posts in this topic

Hello everyone,

I have huge problem with "Recurison level has been exceeded - AutoIt will quit to prevent stack overflow" in my own Bot.

I have no idea how rebuild my loops for eliminate this type of error.


Here is my code 


#Region ; GUI generated by GUIBuilderNxt Prototype 1.0
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <Misc.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
;#include <nomad.au3>

HotKeySet("{end}","stop") ;end for app kill

Local Const $sFont = "Open Sans" ;font variable
Local $sFile = "angelica.ico" ;icon variable
Global $info_task = "[ Waiting for calibration ]",$info_battlelist = "None",$info_empty = "None",$info_hotkeys = "INACTIVE",$info_100 = "None",$info_mana = "None",$info_food = "None",$info_blank = "None",$info_drop = "None",$info_hand = "None"
Global $hMain = GuiCreate("Auto_Angela_Beta_1.0", 330, 559, -1, -1, $MainStyle)


$label_100 = GuiCtrlCreateLabel("[F4] Mana Point "&"   "&$info_100, 20, 40, 170, 20,-1)
$label_mana = GuiCtrlCreateLabel("[F5] Mana Bar "&"     "&$info_mana, 20, 60, 170, 20,-1)
$label_empty = GuiCtrlCreateLabel("[F6] Nothing "&"        "&$info_empty, 20, 80, 170, 20,-1)
$label_battlelist = GuiCtrlCreateLabel("[F7] Battle List "&"     "&$info_battlelist, 20, 100, 170, 20,-1)
$label_food = GuiCtrlCreateLabel("[F8] Food "&"            "&$info_food, 20, 120, 170, 20,-1)
$label_blank = GuiCtrlCreateLabel("[F9] Blank "&"           "&$info_blank, 20, 140, 170, 20,-1)
$label_drop = GuiCtrlCreateLabel("[F10] Drop "&"          "&$info_drop, 20, 160, 170, 20,-1)
$label_hand = GuiCtrlCreateLabel("[F11] Hand "&"         "&$info_hand, 20, 180, 170, 20,-1)
$Group_11 = GuiCtrlCreateGroup("Configuration", 10, 10, 190, 220,-1)
$Group_12 = GuiCtrlCreateGroup("Setup", 210, 10, 110, 220,-1)
$btn_setting = GuiCtrlCreateButton("Setup", 220, 40, 70, 30,-1)
$btn_load = GuiCtrlCreateButton("Load", 220, 100, 70, 30,-1)
$btn_save = GuiCtrlCreateButton("Save", 220, 140, 70, 30,-1)
$label_hotkeys = GuiCtrlCreateLabel("Status: "&$info_hotkeys, 220, 190, 90, 20,-1)
$input_spell = GuiCtrlCreateInput("Adura Vita", 20, 270, 120, 20,-1)
$box_house_mode = GuiCtrlCreateCheckbox("House mode", 20, 300, 90, 20,-1)
$box_pk_mode = GuiCtrlCreateCheckbox("Anty PK", 20, 330, 90, 20,-1)
$Checkbox_20 = GuiCtrlCreateCheckbox("Alarms", 20, 360, 90, 20,-1)
$Checkbox_21 = GuiCtrlCreateCheckbox("Anty Idle", 20, 390, 90, 20,-1)
$btn_auto = GuiCtrlCreateButton("Start", 200, 360, 70, 30,-1)
$btn_refiler = GuiCtrlCreateButton("Rune thrower", 200, 400, 70, 20,-1);$btn_manual = GuiCtrlCreateButton("Start", 200, 360, 70, 30,-1)
$Input_22 = GuiCtrlCreateInput("down", 140, 300, 60, 20,-1)
$Input_23 = GuiCtrlCreateInput("up", 210, 300, 60, 20,-1)
$Group_24 = GuiCtrlCreateGroup("Mode", 10, 250, 310, 180,-1)
GUISetFont(9, $FW_SEMIBOLD) ;white color and bigger font
;$label_task = GuiCtrlCreateLabel($info_task, 10, 450, 370, 24,-1)
GUICtrlSetColor($label_task, 0xffffff)
$Label_28 = GuiCtrlCreateLabel("Auto_Angela_Beta 1.1 @ Medivia 2016", 60, 530, 370, 20,-1)

Global $way_one
Global $way_one

Global $food_pos_x,$food_pos_y
Global $hand_pos_x,$hand_pos_y

Global $drop_pos_x,$drop_pos_y
Global $blank_pos_x, $blank_pos_y

Global $RunOrNot
Global $pid
Global $hotkeys = 0 ;By default hotkeys are disabled

Global $mana_color, $battle_color
Global $mana_100_x,$mana_100_y
Global $mana_pixel_x, $mana_pixel_y
Global $empty_pixel_x = 000, $empty_pixel_y = 000
Global $battle_pixel_x, $battle_pixel_y
Global $is_break
;Global $MapClickEscape_x, $MapClickEscape_y
GUISetBkColor(0x788190) ; will change background color
;GUICtrlSetBkColor($label_hand, 0xF0F4F9)


    Switch GuiGetMsg()
        Case $GUI_EVENT_CLOSE

        Case $btn_setting
            _EnableDisable() ;function which make hotkeys enable/disable

        Case $btn_auto
            IF $info_food <> "None" OR $info_blank <> "None" OR $info_drop <> "None" OR $info_hand <> "None" OR $info_100 <> "None" OR $info_mana <> "None" Then ;simple validation data in possitions variables
               check_mana() ;Function is first in chain for making runes
               MsgBox(0, "Error", "You must setup coordinations")
         Case $btn_load
            load_from_file() ;load data from text file
         Case $btn_save
            save_to_file() ;dave data in text file
         Case $btn_refiler
            refiler() ;for fast refile
Until False

;Func uher()
   ;x,y postaci = F10 DROP
   ;x,y uha w plecaku = F9 Blank
   ;kolor uha pobrany przy ustawieniu
   ;kolor plecaka = F6 BP Color
   ;odpowienio przygotowane staki plecakow

   ;co 400ms sprawdza czy jest dosc hp na uha
   ;jesli trzeba sie uchnac to sprawdza czy w miejscu na uha jest niebieska runa
   ;jesli nie ma to sprawdza czy jest yellow bp jesli nie ma to sygnal dzwiekowy bledu i kill uhera
   ;jesli jest to otwiera plecak i sprawdza czy jest niebieska runa jak nie ma to error i kill uhera
   ;jesli jest to ja przeciaga na postac bardzo szybko

Func refiler()
   local $i = 20
   While $i > 0
      MouseClickDrag($MOUSE_CLICK_LEFT, $blank_pos_x, $blank_pos_y, $drop_pos_x, $drop_pos_y, 1)
      $i = $i - 1

Func save_to_file()
   $file = FileOpen("angela_memory.txt", 1)

   If $file = -1 Then
   MsgBox(0, "Error", "Unable to save data.")
   FileWrite($file, $mana_100_x & @CRLF)
   FileWrite($file, $mana_100_y & @CRLF)

   FileWrite($file, $mana_pixel_x & @CRLF)
   FileWrite($file, $mana_pixel_y & @CRLF)

   FileWrite($file, $empty_pixel_x & @CRLF)
   FileWrite($file, $empty_pixel_y & @CRLF)

   FileWrite($file, $battle_pixel_x & @CRLF)
   FileWrite($file, $battle_pixel_y & @CRLF)

   FileWrite($file, $food_pos_x & @CRLF)
   FileWrite($file, $food_pos_y & @CRLF)

   FileWrite($file, $blank_pos_x & @CRLF)
   FileWrite($file, $blank_pos_y & @CRLF)

   FileWrite($file, $drop_pos_x & @CRLF)
   FileWrite($file, $drop_pos_y & @CRLF)

   FileWrite($file, $hand_pos_x & @CRLF)
   FileWrite($file, $hand_pos_y & @CRLF)

   MsgBox(0, "Done", "Settings saved.")

Func load_from_file()
   $file = FileOpen("angela_memory.txt", $FO_READ)

   If $file = -1 Then
   MsgBox(0, "Error", "Unable to load data.")
   ;wczytywanie segmentow
   $mana_100_x = FileReadLine($file, 1)
   $mana_100_y = FileReadLine($file, 2)
   $info_100 = "X: "&$mana_100_x&"   "&"Y: "&$mana_100_y
   GUICtrlSetData($label_100, "[F4] Mana point "&"   "&$info_100)
   $mana_pixel_x = FileReadLine($file, 3)
   $mana_pixel_y = FileReadLine($file, 4)
   $info_mana = "X: "&$mana_pixel_x&"   "&"Y: "&$mana_pixel_y
   GUICtrlSetData($label_mana, "[F5] Mana Bar "&"     "&$info_mana)
   $empty_pixel_x = FileReadLine($file, 5)
   $empty_pixel_y = FileReadLine($file, 6)
   $info_empty = "X: "&$empty_pixel_x&"   "&"Y: "&$empty_pixel_y
   GUICtrlSetData($label_empty, "[F6] Nothing "&"        "&$info_empty)
   $battle_pixel_x = FileReadLine($file, 7)
   $battle_pixel_y = FileReadLine($file, 8)
   $info_battlelist = "X: "&$battle_pixel_x&"   "&"Y: "&$battle_pixel_y
   GUICtrlSetData($label_battlelist, "[F7] Battle List "&"     "&$info_battlelist)
   $food_pos_x = FileReadLine($file, 9)
   $food_pos_y = FileReadLine($file, 10)
   $info_food = "X: "&$food_pos_x&"   "&"Y: "&$food_pos_y
   GUICtrlSetData($label_food, "[F8] Food "&"            "&$info_food)
   $blank_pos_x = FileReadLine($file, 11)
   $blank_pos_y = FileReadLine($file, 12)
   $info_blank = "X: "&$blank_pos_x&"   "&"Y: "&$blank_pos_y
   GUICtrlSetData($label_blank, "[F9] Blank "&"           "&$info_blank)
   $drop_pos_x = FileReadLine($file, 13)
   $drop_pos_y = FileReadLine($file, 14)
   $info_drop = "X: "&$drop_pos_x&"   "&"Y: "&$drop_pos_y
   GUICtrlSetData($label_drop, "[F10] Drop "&"          "&$info_drop)
   $hand_pos_x = FileReadLine($file, 15)
   $hand_pos_y = FileReadLine($file, 16)
   $info_hand = "X: "&$hand_pos_x&"   "&"Y: "&$hand_pos_y
   GUICtrlSetData($label_hand, "[F11] Hand "&"         "&$info_hand)

   MsgBox(0, "Done", "Settings loaded")

Func stop()

Func kill()
   Exit 0

;functions checking if checkbox checked
Func _IsChecked_pk_mode($box_pk_mode)
    Return BitAND(GUICtrlRead($box_pk_mode), $GUI_CHECKED) = $GUI_CHECKED
EndFunc   ;==>_IsChecked
Func _IsChecked_house_mode($box_house_mode)
    Return BitAND(GUICtrlRead($box_house_mode), $GUI_CHECKED) = $GUI_CHECKED
EndFunc   ;==>_IsChecked

Func floor_maker()

      ;GUICtrlSetData($label_task, "[ Burning rune.. ]")
      $spell_name = GUICtrlRead($input_spell)
      $way_one = GUICtrlRead($Input_22)
      $way_two = GUICtrlRead($Input_23)

      If _IsChecked_house_mode($box_house_mode) Then
         ControlSend("Medivia","","", "{" & $way_one & "}" )

      MouseClickDrag($MOUSE_CLICK_LEFT, $blank_pos_x, $blank_pos_y, $hand_pos_x, $hand_pos_y, 2)
      MouseClickDrag($MOUSE_CLICK_LEFT, $hand_pos_x, $hand_pos_y, $drop_pos_x, $drop_pos_y, 2)
      MouseClick($MOUSE_CLICK_RIGHT, $food_pos_x, $food_pos_y, 4, 10)
      MouseClick($MOUSE_CLICK_RIGHT, $food_pos_x, $food_pos_y, 4, 10)
      If _IsChecked_house_mode($box_house_mode) Then
         ControlSend("Medivia","","", "{" & $way_two & "}" )
      Beep(1000, 150)


Func _EnableDisable()
   If $hotkeys = 0 Then
      HotKeySet("{F4}", "mana_100")
      HotKeySet("{F5}", "mana_get_color")
      ;HotKeySet("{F6}", "MapClickEscape")
      HotKeySet("{F7}", "battle_get_color");Pobiera kolor do zmiennej $battle_color
      HotKeySet("{F8}", "mouse_pos_food")
      HotKeySet("{F9}", "mouse_pos_blank")
      HotKeySet("{F10}", "mouse_pos_drop")
      HotKeySet("{F11}", "mouse_pos_hand")
      $hotkeys = 1
      $info_hotkeys = "ACTIVE"
      GUICtrlSetData($label_hotkeys, "Status: "&" "&$info_hotkeys)
      GUICtrlSetData($label_task, "[ Calibration in progress ]")
      $hotkeys = 0
      $info_hotkeys = "INACTIVE"
      GUICtrlSetData($label_hotkeys, "Status: "&" "&$info_hotkeys)
      GUICtrlSetData($label_task, "[ End of calibration ]")

Func check_mana()
   $current_color = PixelGetColor($mana_100_x,$mana_100_y) ;Taking current color from defined mana break point on maan bar
   $BattleListColor = PixelGetColor($battle_pixel_x, $battle_pixel_y) ;Taking current color from defined posiotion on battle list

   If _IsChecked_pk_mode($box_pk_mode) Then ;only if pk_mode checkbox is checked
      If $BattleListColor = $battle_color Then ;If collor on battle list point didnt change, means nothing (player/monster) enter on out screen
         $RunOrNot = True
         $RunOrNot = False

   If Not ($RunOrNot = False) Then ;If variable RunOrNot are not false it mean is true = is safe
      If $mana_color = $current_color Then ;If mana color flood mana bar break point
         floor_maker() ;rune making function
         ;GUICtrlSetData($label_task, "[ Waiting for mana.. ]")
         check_mana() ;Mana arnt ready so back to mana checking
   Else ;If not safty then run escape function

Func runforestrun()
      $way_one = GUICtrlRead($Input_22)
      $way_two = GUICtrlRead($Input_23)
      ControlSend("Medivia","","", "{" & $way_one & "}" )
         ;GUICtrlSetData($label_task, "[ Not safty outside!! ]")
         $BattleListColor = PixelGetColor($battle_pixel_x, $battle_pixel_y)
         If $BattleListColor = $battle_color Then
            $RunOrNot = True
            $RunOrNot = False
      Until $RunOrNot = True
      MouseClick($MOUSE_CLICK_RIGHT, $food_pos_x, $food_pos_y, 4)
      ControlSend("Medivia","","", "{" & $way_two & "}" )

Func mana_100()
   $pos = MouseGetPos()
   $mana_100_x = $pos[0]
   $mana_100_y = $pos[1]
   $info_100 = "X: "&$mana_100_x&"   "&"Y: "&$mana_100_y
   GUICtrlSetData($label_100, "[F4] Mana point "&"   "&$info_100)

Func mana_get_color()
   $pos = MouseGetPos()
   $mana_pixel_x = $pos[0]
   $mana_pixel_y = $pos[1]
   $mana_color = PixelGetColor($mana_pixel_x, $mana_pixel_y)
   $info_mana = "X: "&$mana_pixel_x&"   "&"Y: "&$mana_pixel_y
   GUICtrlSetData($label_mana, "[F5] Mana Bar "&"     "&$info_mana)

Func battle_get_color()
   $pos = MouseGetPos()
   $battle_pixel_x = $pos[0]
   $battle_pixel_y = $pos[1]
   $battle_color = PixelGetColor($battle_pixel_x, $battle_pixel_y)
   $info_battlelist = "X: "&$battle_pixel_x&"   "&"Y: "&$battle_pixel_y
   GUICtrlSetData($label_battlelist, "[F7] Battle List "&"     "&$info_battlelist)

Func mouse_pos_food()
   $pos = MouseGetPos()
   $food_pos_x = $pos[0]
   $food_pos_y = $pos[1]
   $info_food = "X: "&$food_pos_x&"   "&"Y: "&$food_pos_y
   GUICtrlSetData($label_food, "[F8] Food "&"            "&$info_food)

Func mouse_pos_hand()
   $pos = MouseGetPos()
   $hand_pos_x = $pos[0]
   $hand_pos_y = $pos[1]
   $info_hand = "X: "&$hand_pos_x&"   "&"Y: "&$hand_pos_y
   GUICtrlSetData($label_hand, "[F11] Hand "&"          "&$info_hand)

Func mouse_pos_drop()
   $pos = MouseGetPos()
   $drop_pos_x = $pos[0]
   $drop_pos_y = $pos[1]
   $info_drop = "X: "&$drop_pos_x&"   "&"Y: "&$drop_pos_y
   GUICtrlSetData($label_drop, "[F10] Drop "&"          "&$info_drop)

Func mouse_pos_blank()
   $pos = MouseGetPos()
   $blank_pos_x = $pos[0]
   $blank_pos_y = $pos[1]
   $info_blank = "X: "&$blank_pos_x&"   "&"Y: "&$blank_pos_y
   GUICtrlSetData($label_blank, "[F9] Blank "&"          "&$info_blank)

Func afk()


Share this post

Link to post
Share on other sites

Hi! First of all i feel like i should mention game automation discussion is not allowed, and by looking at your code i gather that's what this bot is?

However! I realize your problem is not necessarily helping with game automation, but to avoid the problem in the feature.

So i think i know where this error happens. Within your function "check_mana" you've made it so it can call itself, within itself. This could be theoretically infinite, so you get a stack overflow. IF you need repetition of functionality, use a loop within the function. A function calling itself is mostly not a good idea.

Also: "check_mana" calls "runforestrun" whitch can call "check_mana", again making a possible infinite loop.

Hope this solves your problem :)

Share this post

Link to post
Share on other sites

Yes, but I cant see different way to do this. 


floor_maker after making magic rune call function check_mana() 

check_mana - this function first checking some condition after that checking mana status, if mana is not ready need call itself for checking this first condition and again mana. If mana is ready call floor_maker for make new rune and then we need to call check_mana again. 

Share this post

Link to post
Share on other sites

Honestly, then maybe you should look into smaller projects, to get a better idea, as to how.

AdlibRegister might be a solution. For right now it seems that the GUI loop is being blocked by "check_mana".

And "floor_maker" does not need to call "check_mana".

Share this post

Link to post
Share on other sites
This topic is now closed to further replies.

  • Similar Content

    • nikink
      By nikink
      Hi all,
      I have a bit of code that works on my old Win10 PC, that fails on my new Win10 PC, and I think the only significant difference is the version of Autoit - old PC has 3.3.12, new has 3.3.14.
      I couldn't find anything mentioned in the change logs though, so perhaps I'm wrong.
      Anyway, the code to replicate my issue is:
      Test('username', 'DOMAIN') ; THIS ERRORS: ;Test('localun', 'DOMAIN') ; THIS ERRORS: ;Test(' ', ' ') ; THIS ERRORS: ;Test('', '') ; THIS ERRORS: ;Test('localun', '') ; THIS ERRORS: ;Test('', 'DOMAIN') Func Test($un, $dom) $compName = 'PCNAME' $FullName = '.' $Description = '.' ; get the WIM object $objWMIService = ObjGet("winmgmts:\\" & $compName & "\root\cimv2") ; get default user full name and description $objAccount = $objWMIService.Get("Win32_UserAccount.Name='" & $un & "',Domain='" & $dom & "'") If IsObj($objAccount) Then $FullName = $objAccount.FullName $Description = $objAccount.Description EndIf ConsoleWrite($FullName & @CRLF) ConsoleWrite($Description & @CRLF) Return EndFunc  
      On my old PC this code will output just . and . for each of those line currently commented out. Which is fine.
      On my new PC any of those commented out lines of code cause an error, and the script won't even compile.
      $objAccount = $objWMIService.Get("Win32_UserAccount.Name='" & $un & "',Domain='" & $dom & "'") $objAccount = $objWMIService^ ERROR I'm very much a newb with the WMI stuff and objects, but it looks like the .Get property is failing when either $un or $dom aren't valid in v3.3.14, whereas in 3.3.12 the .Get would fail to return an object, which is then caught by the If statement.
      Am I on track with this? Is there some new/better way to code the example so that 3.3.14 will compile it?
    • argumentum
      By argumentum
      UDF to intercept the error window of AutoIt, showing more details about the error, including ability to save and send by email!
    • SkysLastChance
      By SkysLastChance
      I get this error, Whenever I try to find a date. Does anyone have any idea why? I saw some post from 2015, However I would imagine this is fixed by now. @water
      >"J:\Temporary Files\XXXXXXXXX\AutoIt\AutoIt\AutoIt\SciTe\..\autoit3.exe" /ErrorStdOut "C:\Users\XXXXXX\Desktop\Call Report Automation.au3"     "J:\Temporary Files\XXXXXXXX\AutoIt\AutoIt\AutoIt\Include\Excel.au3" (656) : ==> The requested action with this object has failed.: $aResult[$iIndex][1] = $oMatch.Name.Name $aResult[$iIndex][1] = $oMatch^ ERROR >Exit code: 1    Time: 5.791 #include <Excel.au3> Global $sExcelFile1 = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "(*.xlsm)") Global $sExcelFile2 = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "Excel Sheet (*.xlsx;*.xls)|All (*.*)") If FileExists($sExcelFile2) Then Global $oExcel2 = _Excel_Open () $oExcel2 = _Excel_BookOpen($oExcel2,$sExcelFile2) EndIF If FileExists($sExcelFile1) Then Global $oExcel1 = _Excel_Open () $oExcel1 = _Excel_BookOpen($oExcel1,$sExcelFile1,Default,Default,"2007") EndIF $oRead = _Excel_RangeRead ($oExcel2,Default,"A2",3) _Excel_RangeWrite ($oExcel1,"Calls Handled",$oRead,"BY7") Sleep (1000) _Excel_RangeFind ($oExcel1,$oRead,"E4:FD92") MsgBox (0,"Test",$oRead) UPDATE:
      If I take out this line it works. By works I mean I don't get the error. :/  However, I need it. I am just confused.
      _Excel_RangeWrite ($oExcel1,"Calls Handled",$oRead,"BY7")  
      UPDATE 2: I also get this error when trying to use the helpfile examples. I have version
      \AutoIt\AutoIt\AutoIt\Include\Excel.au3" (670) : ==> The requested action with this object has failed.: $oSheet = $oWorkbook.Sheets($iIndexSheets) $oSheet = $oWorkbook^ ERROR >Exit code: 1 Time: 0.8931  
    • SkysLastChance
      By SkysLastChance
      How would I go about writing a IF Then statement if the conrol send fails?
      Run ("Notepad.exe") WinWaitActive ("Untitled - Notepad") ControlSend("Untitled - Notepad", "", "Edit1", ("Provider Practice Record")) I have been running into lag alot. So my script has been missing input. I would like to be able to have it retry to put in "Provider Practice Record" if it misses. 
      I am assuming  a if then statement is what I need but I am not sure what ControlSend will return if it tries to send to Edit1 and it is not there. 
      Or do I need to just add a timeout? 
    • ChipConnJohn
      By ChipConnJohn
      Hello all,
      I'm trying to create a webscrape script using AutoIt.  A non-profit I'm involved with is using and there is no notification to the group when someone posts a new topic to the forum.  I'm including IE.au3

      #include <MsgBoxConstants.au3>
      #include <Array.au3>
      #include <String.au3>
      ; Open
      Global $oIE = _IECreate ("")
      ;Grab all the links on the Forum page
      Global $oLinksCategoryPage = _IELinkGetCollection($oIE)
      For $oLink In $oLinksCategoryPage
          Local $oLinkHRef = $oLink.href
          If StringInStr($oLinkHRef,"forum_id") Then
              ;This is a category. Click into it.
              ;Back out to Category List