Sign in to follow this  
Followers 0
joker17

if @error then else doesn't work

13 posts in this topic

if ($resW==1024) Then
    $coord = PixelSearch (400, 15, 568, 30, 0xFE2734)
    ElseIf ($resW==1280) Then
    $coord = PixelSearch (500, 20, 710, 40, 0xFE2734)
    endif
    
    
        if @error Then
send("ciao")
    Else    
send ("byebye")
endif

Ok autoit recognize the pixel and teh variable correctly and if there is the error it correctly send "ciao" but if there is no error it does'nt send byebye why?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

if ($resW==1024) Then
    $coord = PixelSearch (400, 15, 568, 30, 0xFE2734)
    ElseIf ($resW==1280) Then
    $coord = PixelSearch (500, 20, 710, 40, 0xFE2734)
    endif
    
    
        if @error Then
send("ciao")
    Else    
send ("byebye")
endif

Ok autoit recognize the pixel and teh variable correctly and if there is the error it correctly send "ciao" but if there is no error it does'nt send byebye why?

What is it sending it to? Send() just sends to the currently active Window/Control. If the condition that generates the @error also means the desired Window/Control are not active, then "byebye" is being sent somewhere else (where it may just be ignored).

<_<

P.S. Use ControlSend() instead to ensure it goes to the intended Window/Control.

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

the send is just a sample, instead of putting in the original code (that i've tested and works 100%) that is too long

Share this post


Link to post
Share on other sites

When it doesn't send byebye, does it send ciao instead, or just nothing at all?

Share this post


Link to post
Share on other sites

When it doesn't send byebye, does it send ciao instead, or just nothing at all?

nothing at all

Share this post


Link to post
Share on other sites

I don't see why not. I just did this as a test.

Pixelsearch(50,50,60,60,0xFFFFFF,0,1)
  
  if @error Then
msgbox(0,"failed",@error)
    Else    
msgbox(0,"success",@error)
endif

It worked properly, I tried it with both a success and failure.

Share this post


Link to post
Share on other sites

I don't see why not. I just did this as a test.

Pixelsearch(50,50,60,60,0xFFFFFF,0,1)
  
  if @error Then
msgbox(0,"failed",@error)
    Else    
msgbox(0,"success",@error)
endif

It worked properly, I tried it with both a success and failure.

yes man it works even for me if i dont put the 2 pixelsearch into another if sentence

Share this post


Link to post
Share on other sites

the send is just a sample, instead of putting in the original code (that i've tested and works 100%) that is too long

That's the problem with bogus code, it leads to bogus answers. If you want a real answer post the real code.

<_<


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Try this:

If ($resW == 1024) Then
    $l = 400
    $t = 15
    $r = 568
    $b = 30
ElseIf ($resW == 1280) Then
    $l = 500
    $t = 20
    $r = 710
    $b = 40
EndIf

$coord = PixelSearch($l, $t, $r, $b, 0xFE2734)
If @error Then
    Send("ciao")
Else
    Send("byebye")
EndIf
man i'll try this when i come back (i'm going to motorschool, sry bad english) but i think it will work ^^

Share this post


Link to post
Share on other sites

Good luck.

Kind of pointless for me to say, but I tried it with an if statement and it worked as well..

$blah=0;Tried as both zero and one successfully

if ($blah=1) Then
    $coord = PixelSearch (50,50,60,60,0xFFFFFF)
    ElseIf ($blah=0) Then
    $coord = PixelSearch (50,50,60,60,0xFFFFFF)
    endif

  if @error Then
msgbox(0,"failed",@error)
    Else    
msgbox(0,"success",@error)
endif

Share this post


Link to post
Share on other sites

yes man it works even for me if i dont put the 2 pixelsearch into another if sentence

The If/Else/EndIf clauses have nothing to do with it. This works fine:

For $n = 1 To 20
    If Random(0, 1, 1) Then
        PixelSearch(50, 50, 60, 60, 0xF, 0, 1)
    Else
        PixelSearch(50, 50, 60, 60, 0xFFFFFF, 0, 1)
    EndIf

    If @error Then
        ConsoleWrite("failed: " & @error & @LF)
    Else
        ConsoleWrite("success" & @LF)
    EndIf
Next

<_<


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

There's nothing wrong with @error... Remember, 99% of ALL errors is a problem with the wetware (specifically: Syntax Errors), not the software.

You're probably using a function that doesn't set @error. There are functions that do that, such as WinWaitActive(). WinWaitActive returns 1 or 0, and doesn't set @error, but it WILL reset @error to zero. Remember, @error is reset by ANY funciton. User Defined or otherwise.

If you need to save the state of @error store it into a variable immediately after exiting the particular funciton you're testing.

Edited by Blue_Drache

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

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