Jump to content

really big if


Recommended Posts

  • Moderators

part of my code is a really REALLY big if statement. it has like 16 'and's.

is there a way to short it from like a 3 meter long line of code to something more reasonable?

and yes, i DO need the 16 'and's. i'm comparing something to something else using PixelGetColor().

If they're mandatory you could do two things.

1. Put the items in an array and do a For/Next loop to check them.

2. Using an underscore is a line continuation.

Without code, there's no real way to show you... but the line continuation could look something like:

If $condition1 = $condition2 AND _
    $conditon3 = $condition4 AND _
    $condition5 = $condition5 AND _
    $ETC = $ETC Then

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

part of my code is a really REALLY big if statement. it has like 16 'and's.

is there a way to short it from like a 3 meter long line of code to something more reasonable?

and yes, i DO need the 16 'and's. i'm comparing something to something else using PixelGetColor().

Another possibility

$result = True
For $n = 1 To 16
    Switch $n
        Case 1
            $result = Codition1
        Case 2
            $result = Codition2
        ;.
        ;.
        ;.
    EndSwitch
    If Not $result Then ExitLoop
    
Next

If $result Then
;code
EndIf

Or if you could put the conditions into an array maybe

If MultiIf() then
;code

endif


Func MultiIf()
For $n = 0 To 15
    If Not $Condition[$n] Then return False 
Next
 Return $True

endfunc
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

no, no, my code is something like this (though, the example is shorter...)

dim const $target1=123456789
dim const $target2=987654321

if pixelgetcolor(x,y)=$target1 and pixelgetcolor(x,y)=$target1 and pixelgetcolor(x,y)=$target2

except i'm testing ALOT of points to make sure the thing i'm looking for is indeed there.

i want to shorter the large if to something more reasonable.

Link to comment
Share on other sites

no, no, my code is something like this (though, the example is shorter...)

dim const $target1=123456789
dim const $target2=987654321

if pixelgetcolor(x,y)=$target1 and pixelgetcolor(x,y)=$target1 and pixelgetcolor(x,y)=$target2

except i'm testing ALOT of points to make sure the thing i'm looking for is indeed there.

i want to shorter the large if to something more reasonable.

He just told you.

If they're mandatory you could do two things.

1. Put the items in an array and do a For/Next loop to check them.

2. Using an underscore is a line continuation.

Without code, there's no real way to show you... but the line continuation could look something like:

If $condition1 = $condition2 AND _
    $conditon3 = $condition4 AND _
    $condition5 = $condition5 AND _
    $ETC = $ETC Then
If x's and y's are random positions then you can shorten it.
Link to comment
Share on other sites

  • Developers

i want to shorter the large if to something more reasonable.

whats wrong with the multiple line approach as suggested or just use multiple if's

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

no, no, my code is something like this (though, the example is shorter...)

dim const $target1=123456789
dim const $target2=987654321

if pixelgetcolor(x,y)=$target1 and pixelgetcolor(x,y)=$target1 and pixelgetcolor(x,y)=$target2

except i'm testing ALOT of points to make sure the thing i'm looking for is indeed there.

i want to shorter the large if to something more reasonable.

As it seems like you are looking for a certain image on screen check if following threads are helpfull

http://www.autoitscript.com/forum/index.php?showtopic=66545

http://www.autoitscript.com/forum/index.php?showtopic=65748

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...