Jump to content

three requirements at the same time


Recommended Posts

I'm trying to use "And" but it's not working, do you know why, or how else can I set checking three variables at the same time?

 

$coords = PixelSearch(49,422,237,814,0xFFF43C,1)
$x = PixelSearch($coords[0]-25,$coords[1]-25,$coords[0]+100,$coords[1]+100,0xFCFCFC,10)
$y = PixelSearch(237,442,337,690,0xFCFCFC,10)
$z = PixelSearch(237,566,337,690,0xFCFCFC,10)

If $x = 1 And $y = 0 And $z = 0 Then
   Send("{s 2}")
ElseIf $x = 1 And $y = 0 And $z = 1 Then
   Send("{s}")
   EndIf

 

Edited by beekeeper222
Link to comment
Share on other sites

I'm not sure in which "direction" the script goes, but the following for instance is incorrect :

$x = PixelSearch(...) --> If $x = 1 ...

PixelSearch -> Return Value : a two-element array of pixel's coordinates, not a value like 1 or 0.

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

36 minutes ago, beekeeper222 said:

Doesn't $x =1 mean the same as Not @error, and $x =0 @error? 

The return value of PixelSearch in case of success is an array. On failure @error is set, but this is a separate flag, not a function return.

@beekeeper222 : EDIT -> I removed the example, because i made an error -> will give a new one later !

@beekeeper222 : EDIT2 : Example, but no ready-made solution. You should be able to make progress with that ;). 

Local $bXFound = True, $bYFound = True, $bZFound = True

PixelSearch(237, 442, 337, 690, 0xFFFFFF)
If @error Then  $bXFound = False
PixelSearch(237, 443, 337, 690, 0xFFFFFF)
If @error Then $bXFound = False
PixelSearch(237, 444, 337, 690, 0xFFFFFF)
If @error Then $bXFound = False

Select
    Case (Not $bXFound) And (Not $bYFound) And (Not $bZFound)
        ConsoleWrite("X-FALSE  Y-FALSE  Z-FALSE" & @CRLF)
    Case $bXFound And (Not $bYFound) And (Not $bZFound)
        ConsoleWrite("X-TRUE  Y-FALSE  Z-FALSE" & @CRLF)
    Case $bXFound And (Not $bYFound) And $bZFound
        ConsoleWrite("X-TRUE  Y-FALSE  Z-TRUE" & @CRLF)
    Case $bXFound And $bYFound And $bZFound
        ConsoleWrite("X-TRUE  Y-TRUE  Z-TRUE" & @CRLF)
    Case Else
        ConsoleWrite("others" & @CRLF)
EndSelect

 

Edited by Musashi

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

I think that it is what @Musashi wanted to show you ;)

$coords = PixelSearch(49,422,237,814,0xFFF43C,1)
If @error Then Exit
PixelSearch($coords[0]-25,$coords[1]-25,$coords[0]+100,$coords[1]+100,0xFCFCFC,10)
$x = @error
PixelSearch(237,442,337,690,0xFCFCFC,10)
$y = @error
PixelSearch(237,566,337,690,0xFCFCFC,10)
$z = @error

If not $x And $y And $z Then
   Send("{s 2}")
ElseIf not $x And $y And not $z Then
   Send("s")
EndIf

 

Edited by Nine
Link to comment
Share on other sites

Thanks guys so much for helping.

@Nine why isn't it like that? How would the program know what variables I am referring PixelSearch to?

$coords = PixelSearch(49,422,237,814,0xFFF43C,1)
If @error Then Exit
$x = PixelSearch($coords[0]-25,$coords[1]-25,$coords[0]+100,$coords[1]+100,0xFCFCFC,10)
$x = @error
$y = PixelSearch(237,442,337,690,0xFCFCFC,10)
$y = @error
$z = PixelSearch(237,566,337,690,0xFCFCFC,10)
$z = @error

If not $x And $y And $z Then
   Send("{s 2}")
ElseIf not $x And $y And not $z Then
   Send("s")
EndIf

 

Edited by beekeeper222
Link to comment
Share on other sites

Like @Musashi told you, the PixelSearch function return an array of coordinates (X and Y) if successful, otherwise it returns nothing.  To check for success you need to look at @error.  Like all functions in AutoIt, it is not mandatory to capture the return value.  If you do not need the return value, then do not capture it (simple as that).

If you insist of capturing the return value, you could check for success or failure by testing if the return value is an array or not using IsArray ($x).

In your snippet, it is useless to capture return value of PixelSearch, since you are overwriting the the variables right after when assigning it to @error.

Edited by Nine
Link to comment
Share on other sites

It's giving me error, maybe I can do that? 

$coords = PixelSearch(49,422,237,814,0xFFF43C,1)
$x = PixelSearch($coords[0]-25,$coords[1]-25,$coords[0]+100,$coords[1]+100,0xFCFCFC,10)
$y = PixelSearch(237,442,337,690,0xFCFCFC,10)
$z = PixelSearch(237,566,337,690,0xFCFCFC,10)

If IsArray($x) And Not IsArray($y) And Not IsArray($z) Then
   Send("{s 2}")
ElseIf IsArray($x) And Not IsArray($y) And Isarray($z) Then
   Send("{s}")
   EndIf

 

Link to comment
Share on other sites

@beekeeper222 :

You may want to familiarize yourself with some of the basics, so that you can understand the context better. Macros such as @error and @extended are set within most functions, but are not equivalent to the return value of the function itself. How this is handled within the particular functions can be found in the Help under "Return Value".

Example :

; Function IsArray()
; Return Value :
;   Success: 1 (if parameter is an array variable)
;   Failure: 0 (if parameter is not an array variable)
Local $aArray[3] = ["One", "Two", "Three"]
Local $iValue    = 42
ConsoleWrite("> >>> is $aArray an array = " & IsArray($aArray) & @CRLF)
ConsoleWrite("> >>> is $iValue an array = " & IsArray($iValue) & @CRLF)

As you can see, this function returns a value for both cases.

In Pixelsearch, there is no return value in case of failure, as @Nine has already explained. Help : Failure: sets the @error flag to 1 if the color is not found. @error must therefore be queried explicitly.

One more aspect should be considered regarding @error and @extended. These macros are usually reset after calling another function (even ConsoleWrite). Therefore it is recommended to save them in a variable.

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

48 minutes ago, beekeeper222 said:

It's giving me error, maybe I can do that? 

$coords = PixelSearch(49,422,237,814,0xFFF43C,1)
$x = PixelSearch($coords[0]-25,$coords[1]-25,$coords[0]+100,$coords[1]+100,0xFCFCFC,10)
$y = PixelSearch(237,442,337,690,0xFCFCFC,10)
$z = PixelSearch(237,566,337,690,0xFCFCFC,10)

If IsArray($x) And Not IsArray($y) And Not IsArray($z) Then
   Send("{s 2}")
ElseIf IsArray($x) And Not IsArray($y) And Isarray($z) Then
   Send("{s}")
   EndIf

 

No, since if

$coords = PixelSearch(49,422,237,814,0xFFF43C,1)

fails, then the line

$x = PixelSearch($coords[0]-25,$coords[1]-25,$coords[0]+100,$coords[1]+100,0xFCFCFC,10)

will throw an error (==> Subscript used on non-accessible variable) because the array $coords does not exist. 

For this reason, @Nine added the line If @error Then Exit after $coords = ...

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

Also can you guys help me with setting up Pixel Search, i need to search for one pixel on some area, and then mouse move to that pixel, but on the screen are appearing multiple pixels at the same time, so I want to move mouse between them randomly till they dissapear?

Link to comment
Share on other sites

18 minutes ago, beekeeper222 said:

i need to search for one pixel on some area, and then mouse move to that pixel, but on the screen are appearing multiple pixels at the same time, so I want to move mouse between them randomly till they dissapear?

Hmm, now we are slowly but steadily entering a realm where I should ask the following question :

"What exactly do you want to achieve with your script?"

As you may know, PixelSearch is often used in connection with mouse operations to automatize e.g. Games. I am not a moderator, but I would like to point out, that according to our forum-rules such automatizations are not supported. A more detailed description of your objectives would therefore be beneficial before further assistance can be provided.

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

Trying to make a bot that scrolls trough a book and counts how many pages are in a single chapter, all the chapters are separated with a navy blue line, but sometimes there are two blue lines on a single page because writer added the same line before the references, and when it happens, bot stops working. 

Link to comment
Share on other sites

17 minutes ago, beekeeper222 said:

Trying to make a bot that scrolls trough a book and counts how many pages are in a single chapter ...

This does not sound entirely implausible to me. However, I would still like to ask a moderator how he or she evaluates the issue. A response usually comes pretty fast. I hope you don't have a problem with that.

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

5 hours ago, beekeeper222 said:

Sure, I can apply a screenshot of the book or a code I'm currently stucked with if there will be any uncertainty.

I think that's a good idea. On the one hand, it probably helps the moderator in his/her evaluation. If the feedback is positive, this information will also help users, who are willing and able to give further assistance ;).

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

  • Moderators

beekeeper222, 

A screenshot of the book would be just the thing please. 

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

beekeeper222,

Perfect, thank you.  Thread clear to continue.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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