Jump to content

Simples question (if @error)


 Share

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
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.

Link to comment
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

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
Link to comment
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?

Link to comment
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?

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...