Sign in to follow this  
Followers 0
GodForsakenSoul

really big if

8 posts in this topic

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

Share this post


Link to post
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().

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.

Share this post


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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites

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

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

@aassdd: Wtf i didn't see that post earlier :);;

thanks for pointing that out.

Share this post


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

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