|
You last visited: Today at 10:04
Advertisement
help avoid recursion
Discussion on help avoid recursion within the AutoIt forum part of the Coders Den category.
12/12/2013, 11:32
|
#1
|
elite*gold: 0
Join Date: Jun 2006
Posts: 19
Received Thanks: 2
|
help avoid recursion
i have a script that works very nicely but recursion ocures very often because of the internal loop
can anyone rewrite this code so recursion wont apear and basicly will do the same thing??
Code:
HotKeySet("{F10}", "first")
While 1
Sleep(100)
WEnd
Func first()
Send("{SPACE}")
While 1
$pix = PixelSearch(429, 552, 431, 554, 0x548E04, 10)
If Not @error Then
Send("{SPACE DOWN}")
Call("second")
EndIf
WEnd
EndFunc ;==>first
Func second()
While 1
$pix2 = PixelSearch(506, 552, 508, 554, 0x709F05, 10)
If Not @error Then
Send("{SPACE UP}")
Call("third")
EndIf
WEnd
EndFunc ;==>second
Func third()
While 1
$pix3 = PixelSearch(424, 552, 426, 554, 0x5B4321, 10)
If Not @error Then
Send("{SPACE DOWN}")
Call("second")
EndIf
WEnd
EndFunc ;==>third
|
|
|
12/12/2013, 11:36
|
#2
|
elite*gold: 3570
Join Date: Dec 2012
Posts: 13,044
Received Thanks: 8,252
|
Why don't you write all in one function?
|
|
|
12/12/2013, 11:39
|
#3
|
elite*gold: 0
Join Date: Jun 2006
Posts: 19
Received Thanks: 2
|
because i dont know amost anithing about autoit,a guy made me this script what works like a charm,only overbuffers the dataflow because of the internal loop after 30 minutes ore so of using it
|
|
|
12/12/2013, 12:55
|
#4
|
elite*gold: 60
Join Date: Aug 2009
Posts: 2,256
Received Thanks: 815
|
The recursion level is quiet low so I would write this script without recursion, you can try this:
Code:
HotKeySet("{F10}", "_Run")
While 1
Sleep(100)
WEnd
Func _Run()
Local $iState = 0
While 1
If $iState = 0 Then
Send("{SPACE}")
While $iState = 0
$pix = PixelSearch(429, 552, 431, 554, 0x548E04, 10)
If Not @error Then
Send("{SPACE DOWN}")
$iState = 1
EndIf
WEnd
ElseIf $iState = 1 Then
While $iState = 1
$pix2 = PixelSearch(506, 552, 508, 554, 0x709F05, 10)
If Not @error Then
Send("{SPACE UP}")
$iState = 2
EndIf
WEnd
ElseIf $iState = 2 Then
While $iState = 2
$pix3 = PixelSearch(424, 552, 426, 554, 0x5B4321, 10)
If Not @error Then
Send("{SPACE DOWN}")
$iState = 1
EndIf
WEnd
EndIf
WEnd
EndFunc
I didn't test it because I can't recreate the environment you have so you have to test it and maybe make some adjustments.
|
|
|
12/12/2013, 14:37
|
#5
|
elite*gold: 0
Join Date: Jun 2006
Posts: 19
Received Thanks: 2
|
it works,i will come with feedback in 2 3 days
|
|
|
12/12/2013, 18:23
|
#6
|
elite*gold: 0
Join Date: Mar 2009
Posts: 7,260
Received Thanks: 33,149
|
Code:
Dim $arr[3][6] = [ [429, 552, 431, 554, 0x548E04, "{SPACE DOWN}"], _
[506, 552, 508, 554, 0x709F05, "{SPACE UP}"], _
[424, 552, 426, 554, 0x5B4321, "{SPACE DOWN}"]]
Dim $i = 0, $run = False
HotKeySet("{F10}", "_TogglePause")
Func _TogglePause()
$run = Not $run
If $run Then
$i = 0
Send("{SPACE}")
EndIf
EndFunc
While Sleep(100)
While $run
If $i > 2 Then $i = 1
PixelSearch($arr[0], $arr[1], $arr[2], $arr[3], $arr[4], 10)
If Not @error Then
Send($arr[5])
$i += 1
EndIf
WEnd
WEnd
|
|
|
12/12/2013, 18:48
|
#7
|
elite*gold: 64
Join Date: May 2011
Posts: 1,229
Received Thanks: 854
|
KDeluxe dein Script würde nicht funktioniert.
Da du $arr als 2 Dimensionale Array deklariert hast.
Aber sie als 1 Dimensionale nutzt.
|
|
|
12/12/2013, 19:07
|
#8
|
elite*gold: 60
Join Date: Aug 2009
Posts: 2,256
Received Thanks: 815
|
Quote:
Originally Posted by BladeTiger12
KDeluxe dein Script würde nicht funktioniert.
Da du $arr als 2 Dimensionale Array deklariert hast.
Aber sie als 1 Dimensionale nutzt.
|
1. das, 2. selbst wenn es gehen sollte, spricht er das 4. Element eines 2D-Arrays an was nicht existiert.
Außerdem heißt es doch nicht "dein Script würde nicht funktioniert."
Was war denn da los?
|
|
|
12/12/2013, 21:48
|
#9
|
elite*gold: 280
Join Date: May 2007
Posts: 2,818
Received Thanks: 3,483
|
er benutzt sehr wohl ein 2d array <.<
das einzige was er vergessen hat, ist den index mit zu nutzen...
korrekt würde es so aussehen:
Code:
Dim $arr[3][6] = [ [429, 552, 431, 554, 0x548E04, "{SPACE DOWN}"], _
[506, 552, 508, 554, 0x709F05, "{SPACE UP}"], _
[424, 552, 426, 554, 0x5B4321, "{SPACE DOWN}"]]
Dim $i = 0, $run = False
HotKeySet("{F10}", "_TogglePause")
Func _TogglePause()
$run = Not $run
If $run Then
$i = 0
Send("{SPACE}")
EndIf
EndFunc
While Sleep(100)
While $run
If $i > 2 Then $i = 1
PixelSearch($arr[$i][0], $arr[$i][1], $arr[$i][2], $arr[$i][3], $arr[$i][4], 10)
If Not @error Then
Send($arr[$i][5])
$i += 1
EndIf
WEnd
WEnd
der größte nachteil an diesem script ist allerdings die verschachtelung der while schleifen. ab der inneren schleife gibt es hier keine cpu entlastung mehr. eine einfache abfrage der $run variable in der hauptschleife wäre hier sinnvoller.
Edit:
fraglich ist auch, ob es hier tatsächlich sinn macht ein array zu nutzen. eventuell sollte man lieber auf eine einfache funktion zur abarbeitung umsteigen...
etwa so:
Code:
HotKeySet("{F10}", "Pause")
Global $globalState=0, $globalRun=False
While Sleep(1)
Action(0, 429, 552, 431, 554, 0x548E04, "{SPACE DOWN}")
Action(1, 506, 552, 508, 554, 0x709F05, "{SPACE UP}")
Action(2, 424, 552, 426, 554, 0x5B4321, "{SPACE DOWN}")
If $globalState >= 2 Then $globalState = 1
WEnd
Func Pause()
$globalRun = Not $globalRun
EndFunc
Func Action($state, $left, $top, $right, $bottom, $color, $send)
If $state=$globalState and $globalRun Then
PixelSearch($left, $top, $right, $bottom, $color, 10)
If not @error Then
Send($send)
$globalState+=1
EndIf
EndIf
EndFunc
so wäre es unter anderem möglich in jedem zustand beliebig viele aktionen durchzuführen.
|
|
|
12/12/2013, 21:54
|
#10
|
elite*gold: 60
Join Date: Aug 2009
Posts: 2,256
Received Thanks: 815
|
Das wurde doch schon erwähnt das die Indexe fehlen.
|
|
|
12/12/2013, 23:50
|
#11
|
elite*gold: 0
Join Date: Mar 2009
Posts: 7,260
Received Thanks: 33,149
|
Mein einziger Fehler besteht allerdings nur darin, dass ich vergessen habe, die 1. Dimension anzugeben. Das kann schon mal passieren, zumal ich die Scripte selbst nicht teste. Als sinnvoll habe ich meine Lösung nie betrachtet, es war spontan das erste was mir eingefallen ist um nur "eine" Anweisung zu verwenden. Rückblickend verstehe ich aber selbst nicht, weshalb ich eine zweite While-Schleife verwendet habe, eigentlich sollte das eine einfache If-Abfrage sein.
Möchte man alles aus dem Script von piku verwenden sollte die Pause() Funktion allerdings so aussehen:
Code:
Func Pause()
$globalRun = Not $globalRun
If $globalRun Then Send("{SPACE}")
EndFunc
Aktuell wird das initiale Send() der first() Funktion nicht beachtet. Bei mir habe ich den Index/Status zusätzlich noch zurückgesetzt. Inwiefern das bei einer "Pause" Funktion tatsächlich sinnvoll ist lässt sich genau sagen.
|
|
|
12/13/2013, 00:52
|
#12
|
elite*gold: 280
Join Date: May 2007
Posts: 2,818
Received Thanks: 3,483
|
Quote:
Originally Posted by KDeluxe
Bei mir habe ich den Index/Status zusätzlich noch zurückgesetzt. Inwiefern das bei einer "Pause" Funktion tatsächlich sinnvoll ist lässt sich genau sagen.
|
richtig, das wäre dann wohl eher ein reset, als eine pause :P
wie dem auch sei, ohne eine genaue projektbeschreibung kann hier ohnehin nur gemutmaßt werden, was der TE tatsächlich will.
|
|
|
 |
Similar Threads
|
Several Questions - Recursion/GUI
09/10/2013 - AutoIt - 3 Replies
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...
|
Recursion level has been exceeded - AutoIt will quit to prevent stack overflow.
01/20/2013 - AutoIt - 4 Replies
Hallo Leute,
ich hab das folgende Problem mit meinem Bot:
Nach ca. 4-5 Std. Laufzeit meines Bots bekomme ich folgende Meldung...
"Recursion level has been exceeded - AutoIt will quit to prevent stack overflow."
Das ganze an völlig unterschiedlichen Stellen, es ist also wirklich die Addition die das Problem hervorruft und nicht eine bestimmte Funktion etc.
|
How to avoid ban
10/28/2011 - 4Story - 1 Replies
Hi as you know buying gold is ilegal and if they faoun out that you did they ban you so i was wondering is there any way to avoid GMS and GA to find out that you buy gold?
|
[Tut] How to Avoid GM
04/07/2010 - Grand Chase Hacks, Bots, Cheats & Exploits - 15 Replies
i have a great methode to Avoid GM's
but it require to know all GM name
NAGC GM LIST:
GM_Bawkzie
GM_Chaos
GM_Grimm
|
[Tut] How to Avoid GM
04/06/2010 - Grand Chase - 0 Replies
i have a great methode to Avoid GM's
but it require to know all GM name
Here are name of GM i know so far( written exacly like in-game):
.GM_Syn
.
.
.
plz post if you know more GM name
|
All times are GMT +1. The time now is 10:04.
|
|