Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > AutoIt
You last visited: Today at 22:03

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Several Questions - Recursion/GUI

Discussion on Several Questions - Recursion/GUI within the AutoIt forum part of the Coders Den category.

Reply
 
Old   #1
 
BitOfHope's Avatar
 
elite*gold: 0
Join Date: Nov 2009
Posts: 71
Received Thanks: 11
Several Questions - Recursion/GUI

Hey guys, been a while since I've posted in this section.

So I've got several questions I need help with:
  • I've encountered the dreaded recursion error in one of my more recent scripts.
  • I've almost completely avoided using a GUI since I started using Autoit. Now that I want to use it I need some help with setting it up. I have several questions for this.

Recursion:
This error has caused me a headache. I've spent time googling this issue and the reason always given is: "You're making a function call itself in an infinite loop."
Code:
Hi()

Func Hi()
   Hi()
EndFunc
This would cause a recursion error. I understand this.

Originally I had part of my script as:
Code:
Func CombatRest()
	Local $coord = PixelSearch($X1, $Y1, $X2, $Y2, 0xFFFFFF) 
	If Not @error Then
		Send($HealSpell)
		Sleep($HealSleep)
		CombatRest()
	ElseIf @error Then
		Sleep(10)
	EndIf
EndFunc   ;==>CombatRest
So I figured that THIS was the problem so I changed it to:
Code:
Func CombatRest()
	Local $coord = PixelSearch($X1, $Y1, $X2, $Y2, 0xFFFFFF) 
	If Not @error Then
		Send($HealSpell)
		Sleep($HealSleep)
	ElseIf @error Then
		Sleep(10)
	EndIf
EndFunc   ;==>CombatRest
Then just simply had the script pull up this function more often. This however did not fix my issue. So then looking through my script I found that I used so many different functions within functions that my script actually never restarted.

All I had to do was send the actual function ONE time at the start of my script, and it went on an infinite loop of functions calling functions until it crashed (After about 1-2 hours of running the script).

So if this IS why I got the recursion error(please confirm this or not) then the solution would be to put my initial:
Code:
While 1
	Function1()
	Function2()
	Function3()
WEnd
And make sure that the loop of it going from function to function doesn't happen and it comes back to my initial While 1 loop. Right? A while 1 loop that actually repeats itself won't cause a recursion error, correct?
~~~~~
GUI:
This part involves several questions. First, I want to include the ability to keep track of how many monsters are killed. So I'm thinking I need to add in a... counter? To the function that confirms when a monster is dead. I already have the function that knows when the monster is dead, but I'm not sure how to write up the counter to the end of the function to add +1 to a display on the GUI. An example function that the counter would be added to would be:
Code:
Func CombatRest()
	Local $coord = PixelSearch($X1, $Y1, $X2, $Y2, 0xFFFFFF) 
	If Not @error Then
		Send($HealSpell)
		Sleep($HealSleep)
	ElseIf @error Then
		Sleep(10)
	EndIf
EndFunc   ;==>CombatRest
~~~~~

Next question: I can make a simple GUI that has a button that you press and it runs a function/or whatever I put there. Something like this:
Code:
GUICreate("BitOfHope's Autocombat Bot", 170, 100)

GUISetState(@SW_SHOW);Allows the GUI to be displayed.

$exitbutton = GUICtrlCreateButton("Info", 90, 70, 80) ;Information

$Button1 = GUICtrlCreateButton("Button 1", 0, 0, 80);First button on the GUI.
$Button2 = GUICtrlCreateButton("Button 2", 0, 25, 80);Second button on the GUI.

$Button3 = GUICtrlCreateButton("Button 3", 90, 0, 80) ;Third button on the GUI.
$Button4 = GUICtrlCreateButton("Button 4", 90, 25, 80) ;Fourth button on the GUI.

While 1
	$msg = GUIGetMsg()

	Select

		Case $msg = $exitbutton
			MsgBox(1, "Read this.", "Placeholder. Information on the bot goes here.");Information button.

		Case $msg = $Button1
			ToolTip("Popup before the script starts.");Popup message before the script starts.
			Sleep(3000)
			ToolTip("");Closes the popup message.
			Sleep(10)
			WinWaitActive($game)
			While 1
				Sleep(1000);This is what happens after you click the button this is in.
			WEnd

		Case $msg = $Button2
			ToolTip("Popup before the script starts.");Popup message before the script starts.
			Sleep(3000)
			ToolTip("");Closes the popup message.
			Sleep(10)
			WinWaitActive($game)
			While 1
				Sleep(1000);This is what happens after you click the button this is in.
			WEnd

		Case $msg = $Button3
			ToolTip("Popup before the script starts.");Popup message before the script starts.
			Sleep(3000)
			ToolTip("");Closes the popup message.
			Sleep(10)
			WinWaitActive($game)
			While 1
				Sleep(1000);This is what happens after you click the button this is in.
			WEnd

		Case $msg = $Button4
			ToolTip("Popup before the script starts.");Popup message before the script starts.
			Sleep(3000)
			ToolTip("");Closes the popup message.
			Sleep(10)
			WinWaitActive($game)
			While 1
				Sleep(1000);This is what happens after you click the button this is in.
			WEnd

		Case $msg = $GUI_EVENT_CLOSE;Closes the GUI.
			GUIDelete()
			ExitLoop

	EndSelect
WEnd
But my question is more complicated and will probably make me sound silly. How would I use 'checkboxes'. If I want an extra line to be added into a function. For example:
Code:
Func CombatRest()
	Local $coord = PixelSearch($X1, $Y1, $X2, $Y2, 0xFFFFFF) 
	If Not @error Then
		Send($HealSpell)
		Sleep($HealSleep)
	ElseIf @error Then
		Sleep(10)
	EndIf
EndFunc   ;==>CombatRest
This would be what runs normally. However, if I were to click a checkbox that tells it to also press the 5 key after it finishes healing, how would I do that? My mind is totally not grasping the concept even though I feel like it's a simple answer.

I'm sure through the course of writing this script I'll come up with several more questions, most likely GUI related. I'll post them here if I do think of them.

Any help is appreciated!
~~~~~

If anybody is willing to help me out some more with general questions as I write this script, if you're up for adding me on skype/msn so I don't have to come back to the forums every time, that would be epic. Send me a PM on here with your skype/msn and I'll add you.

Also, if anybody is curious the bot I'm making is for FFXIV:ARR. I already have a working version but it's a bit buggy and has no GUI. So I'm re-writing it to make it much sexier. If you're up for helping me out with this specific script instead of just general Autoit questions then also feel free to send me a PM with your skype/msn.
BitOfHope is offline  
Old 09/09/2013, 12:40   #2
 
butter123's Avatar
 
elite*gold: 95
Join Date: May 2011
Posts: 982
Received Thanks: 189
1. Recursion: Yes if you always get back to a main loop, you wont get a recursion. (exept if the main loop is inside a function and you call that to get to the main loop again.)

2. Gui,+1:
Make a global counter and if the monster gets killed set it to $i=$i+1. Then call GuiCtrlSetData($Label,$i) after that.

3. Extra line:
Hide it inside an If structure. If GuiCtrlRead($Checkbox) = $GUI_CHECKED then do the extra line. The line will only get executed if the checkbox is checked. ($GUI_UNCHECKED if it should be executed when its not checked)
butter123 is offline  
Thanks
1 User
Old 09/09/2013, 14:45   #3
 
lolkop's Avatar
 
elite*gold: 280
Join Date: May 2007
Posts: 2,818
Received Thanks: 3,483
since gui related stuff should allways react on user interactions, you will have to build some higher logic stuff...

the guigetmsg command grabs the current controlstates and returns the used controls id. this means, if the script stucks for example in sleep functions, the used controls won't get requested.

to realize the smallest possible delays in your code, you will have to learn using state-variables, timers and most important, get rid of all sleep/wait commands in your script.
lolkop is offline  
Thanks
1 User
Old 09/10/2013, 04:14   #4
 
BitOfHope's Avatar
 
elite*gold: 0
Join Date: Nov 2009
Posts: 71
Received Thanks: 11
Thanks guys. You both gave me a good amount of information to use/look more into.
BitOfHope is offline  
Reply




All times are GMT +1. The time now is 22:03.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.