Sign in to follow this  
Followers 0
tiago

Simples question (if @error)

12 posts in this topic

Hi

I wanna know if theres a command line to get back to another line in the top,

something like:

"if @error then go to line 2"

Thanks,

and sorry for my bad inglish, im from Brazil.

Share this post


Link to post
Share on other sites



sorry i dont understand

i mean,

if i got a error on line 30, theres a way to back to line 2 and try everything again?

Share this post


Link to post
Share on other sites

there are many ways to do that...

maybe

do until loop ex

do

......

.....

until NOT @error

then the part in the middle will be reproduced until the function don´t do error... i suggest use small pieces of scipts and do functions with them...

a question what function sets the error?

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

With Autoit, and most evolved languages, you must thing a little diiferently that what you are.

Stop thinking about line numbers and begin thinking about what the code on those lines do.

When you have a few lines of code that perfoms as a function or task, you would write it as such.

Take this code, you can have it run from anywhere in your script, regardless of what line its on, you dont use Goto 2 you simple call the function.

Func _Read()
    $sValue = IniRead("MyIni.ini","SECTION","Key","Fail")
    Return $sValue
EndFunc

EDIT:

If you are having trouble understanding it, then the best thing to do is present some code where you think you would need a goto line, and either myself or someone else will show you how it ought to be done.

To clarify, there is no goto keyword in autoit3

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

allright friends

im trying others methods

something like that

sleep (5000)     
 $coord = PixelSearch( 0, 800, 1400, 170, 0xc5c2c5, 0 ) 
        if true then    MouseClick( "right", $coord[0], $coord[1], 2, 1 )    
    MouseClick("left", $Coord[0]+20, $Coord[1]+30, 8, 1)    
 endif 
 if $coord false Then 
    Send("{F1")     
endif

but its error when pixelsearch fails

how can i send F1 when pixelsearch fails?

Edited by tiago

Share this post


Link to post
Share on other sites

Something like this.

Sleep(5000)
$F1 = Send("{F1}")

While 1
    _Search(); keep searching until it finds your pixel
    If Not @error Then ExitLoop; if the pixel is found and the clicks are performed loop will end.
    Sleep(100)
WEnd


Func _Search()
    $coord = PixelSearch(0, 800, 1400, 170, 0xc5c2c5, 0)
    If @error Then Return SetError(1);if it erroes it returns to the while loop
    MouseClick("right", $coord[0], $coord[1], 2, 1)
    MouseClick("left", $coord[0] + 20, $coord[1] + 30, 8, 1)
EndFunc   ;==>_Search

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Something like this.

Sleep(5000)
$F1 = Send("{F1}")

While 1
    _Search(); keep searching until it finds your pixel
    If Not @error Then ExitLoop; if the pixel is found and the clicks are performed loop will end.
    Sleep(100)
WEnd


Func _Search()
    $coord = PixelSearch(0, 800, 1400, 170, 0xc5c2c5, 0)
    If @error Then Return SetError(1);if it erroes it returns to the while loop
    MouseClick("right", $coord[0], $coord[1], 2, 1)
    MouseClick("left", $coord[0] + 20, $coord[1] + 30, 8, 1)
EndFunc   ;==>_Search

thanks JohnOne it works,

but now how i loop everything?

i wanna keep this running

EDIT: i found,

its just erase "If Not @error Then ExitLoop; if the pixel is found and the clicks are performed loop will end."

i need a hotkey comand to stop the loop

any idea?

Edited by tiago

Share this post


Link to post
Share on other sites

i need a hotkey comand to stop the loop

any idea?

Yes, take a look to HotKeySet. In the example you have the answer.

Share this post


Link to post
Share on other sites

thank you

and if i want to try find another pixel?

i try this:

Func _Search()

$coord = PixelSearch(0, 800, 1400, 170, 0xc5c2c5, 0)

and $coord2 = PixelSearch(0, 800, 1400, 170, 0xff66bf, 0)

i try "and" and(lol) "or" but it doesnt work

and i do this

MouseClick("right", $coord[0], $coord[1], 2, 1)

MouseClick("left", $coord[0] + 30, $coord[1] + 50, 8, 1)

if $coord2 true then

MouseClick("left", $coord2[0], $coord2[1], 1, 1)

endif

where is my fault?

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

thank you

and if i want to try find another pixel?

i try this:

Func _Search()

$coord = PixelSearch(0, 800, 1400, 170, 0xc5c2c5, 0)

and $coord2 = PixelSearch(0, 800, 1400, 170, 0xff66bf, 0)

i try "and" and(lol) "or" but it doesnt work

and i do this

MouseClick("right", $coord[0], $coord[1], 2, 1)

MouseClick("left", $coord[0] + 30, $coord[1] + 50, 8, 1)

if $coord2 true then

MouseClick("left", $coord2[0], $coord2[1], 1, 1)

endif

where is my fault?

first for the better understand between all i suggest use the code format for the code..

second you need to think well what do you want the program do and explain to us...

third you need to understand that you have many errors.. you need to start to try to understand the help..(it help a lot)

fourt return doesn´t mean "return to line blabla...." it means what value do you want the function return.. a value of a handle, a variable, etc

fifht...

...I think that this what you want XD

Func _Search()
    
    $coord = PixelSearch(0, 800, 1400, 170, 0xc5c2c5)               ; I remove the 0 at the end.. is optional
                                                                    
    If Not @error Then                              ; You have to give an answer to an error if you don´t...
                                            ; ...do that the program will crash...
        MouseClick("right", $coord[0], $coord[1], 2, 1)
        
        ;sleep(????)                                ; maybe you need to put some time to delay the other click
        
        MouseClick("left", $coord[0] + 30, $coord[1] + 50, 8, 1)
        
    EndIf
    
    $coord2 = PixelSearch(0, 800, 1400, 170, 0xff66bf)
    
    If Not @error Then
        
        MouseClick("left", $coord2[0], $coord2[1], 1, 1)
        
    EndIf
    
EndFunc   ;==>_Search

Or maybe i´m wrong it will be helpful if you tell us for what is this script

Edited by monoscout999

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