Sign in to follow this  
Followers 0
ShredShred

Problems with understanding how it is working

11 posts in this topic

Hello,

My script has to have few functions:

1)Search for pixel color

a) if function find pixel then start doing second function

2)if function will not find pixel then start doing third function

I know some basics, read FAQ and wiki + examples from other scripts but I do not fully understand why it is working or not.

Since I dont know 100% I can't go further.

While 1

sleep(1000)

Send("start search")

sleep(1000)

_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(1000)

send("search finished")

WEnd

Func _Search()

PixelSearch(1268,267,1297,287,0x531C18,20)

If @error Then Return SetError(1) ;if it erroes it returns to the while loop

sleep(500)

MouseMove(125,125,50)

EndFunc ;==>_Search

Func _Second

Func _Third

Ok then lets try my way of thinking.

If PixelSearch will find pixel then it returns coordinates and @error=0

In This place I want to run Func _Second

If _Search() will not find pixel I want to run Func _Third then start _Search again.

I hope it is clear for you :unsure: Thanks a lot in advance for your help me in understanding how it's should work.

I am not programmer but I am finding Autoit a very easy tool to create almost whatever you want :>

*****************

Share this post


Link to post
Share on other sites



Thank you JohnOne but I know what means shade number in PixelSearch. I tried with many shade numbers from 1 to 255 :unsure: to confirm script is working.

My problem is now how to write code using functions and PixelSearch to run depending on PixelSearch function result :/ I spend 15+ hours on this and I feel like dumb - as I feel it is so simple.

Share this post


Link to post
Share on other sites

Like this?

While 1
    Sleep(1000)
    Send("start search")
    Sleep(1000)
    $b_Rtn = _Search(); keep searching until it finds your pixel
    If $b_Rtn Then
        _Second()
    Else
        _Third()
    EndIf
WEnd

Func _Search()
    PixelSearch(1268, 267, 1297, 287, 0x531C18, 20)
    If @error Then
        Return False
    Else
        Sleep(500)
        MouseMove(125, 125, 50)
        Return True
    EndIf
EndFunc   ;==>_Search

Func _Second()
EndFunc   ;==>_Second
Func _Third()
EndFunc   ;==>_Third

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

Or maybe this:

Global $Test = 10
While $Test
    Sleep(1000)
    ConsoleWrite("start search" & @CRLF)
    Sleep(1000)
    _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.
    Else
        _Third()
    EndIf
    Sleep(1000)
    ConsoleWrite("search finished" & @CRLF)
WEnd
Func _Search()
    PixelSearch(1268, 267, 1297, 287, 0x531C18, 20)
    If @error Then Return SetError(1) ;if it errors it returns to the while loop
    Sleep(500)
    MouseMove(125, 125, 50)
    _Second()
EndFunc   ;==>_Search
Func _Second()
    MsgBox(0, "", "_Second Reached")
EndFunc   ;==>_Second
Func _Third()
    ConsoleWrite("_Third Reached" & @CRLF)
    $Test -= 1
EndFunc   ;==>_Third

This will only run 10 times as written and then exits on its own. That can easily be changed by changing the values for $Test.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Thank you JohnOne & BrewManNH for fast reply. I analize and test your code and let you know about results. Cheers

Edited by ShredShred

Share this post


Link to post
Share on other sites

Thanks John - now I understand why you said 1/20 :unsure: when in fact I wanted to increase chances by using shade varation to find similar pixels also.

Both scripts are working however with my low skill of understanding code John's code is simplier (my brain explode when I have to imagine how program is working with negations "NOT" xD)

Seting up variable as result of function _Search simplified code for me. It is more clear now :>

Thx BrewMan - I learned something more about Dim/Local/Global ;)

I have an issue with PixelSearch. Even if I am sure pixel should be found 2/10 times _Search returns false which ruin script. Tried with shade varation 0-20 and still same. But if there is no pixel for 100% script return false in 100% situtations ....

While $i<6

    $b_Rtn = _Search(); keep searching until it finds your pixel
    Sleep(100)
    $c_Rtn = _Search(); keep searching until it finds your pixel
    Sleep(100)
    $d_Rtn = _Search(); keep searching until it finds your pixel
    Sleep(100)
    $e_Rtn = _Search(); keep searching until it finds your pixel
    Sleep(100)
    $f_Rtn = _Search(); keep searching until it finds your pixel
    Sleep(100)
    $g_Rtn = _Search(); keep searching until it finds your pixel
    Sleep(100)
    $h_Rtn = _Search(); keep searching until it finds your pixel
    Sleep(100)
    If $b_Rtn OR $c_Rtn OR $d_Rtn OR $e_Rtn OR $f_Rtn OR $g_Rtn OR $h_Rtn Then
        RandomDelay1sek()
        Enchanting() ; there was _Second
        $i += 1
    Elseif $b_Rtn=False AND $c_Rtn=False AND $d_Rtn=False AND $e_Rtn=False AND $f_Rtn=False AND $g_Rtn=False AND $h_Rtn=False Then ;
        _Third()
        $i=0

    EndIf
WEnd

To avoid incorrect false results I used multiple search func and logic of result using OR. However it was returning false again 1/10 times. So I used delays 100ms between each searching and it improved situation greatly. Is it possible func is so slow it needs delays?

Another thing Elseif - there would be ok with "Else" only. However with Else it was not working corretly but with Elseif it is working ... another riddle for me.

Share this post


Link to post
Share on other sites

Another thing Elseif - there would be ok with "Else" only. However with Else it was not working corretly but with Elseif it is working ... another riddle for me.

No, an Else would be always true when the If is False. You ElseIF is only True when all "And relations" are True.

Jos


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

Share this post


Link to post
Share on other sites

Added more of my code for better understanding.

In my script if any of six _Search tries find pixel then return True and variable is True

To avoid mistakes when there is pixel in real but search fail and did not find it so it is looking for pixel six times in row so

my If condition are looking for even one True in any variable

1) at least one is true => run _Second()

2) no true in six variables => elseif will check if ALL six variables are False

So in my script If is looking for at least one True and ElseIf for all False. Doesn't it mean Else would mean "there was no True at all = all was False" and do the same as my ElseIf?

Are my assumption clear and codded correctly?

While $i<6

    $b_Rtn = _Search(); keep searching until it finds your pixel
    Sleep(100)
    $c_Rtn = _Search(); keep searching until it finds your pixel
    Sleep(100)
    $d_Rtn = _Search(); keep searching until it finds your pixel
    Sleep(100)
    $e_Rtn = _Search(); keep searching until it finds your pixel
    Sleep(100)
    $f_Rtn = _Search(); keep searching until it finds your pixel
    Sleep(100)
    $g_Rtn = _Search(); keep searching until it finds your pixel
    Sleep(100)
    $h_Rtn = _Search(); keep searching until it finds your pixel
    Sleep(100)
    If $b_Rtn OR $c_Rtn OR $d_Rtn OR $e_Rtn OR $f_Rtn OR $g_Rtn OR $h_Rtn Then
                _Second()
        $i += 1
    Elseif $b_Rtn=False AND $c_Rtn=False AND $d_Rtn=False AND $e_Rtn=False AND $f_Rtn=False AND $g_Rtn=False AND $h_Rtn=False Then ;
        _Third()
        $i=0

    EndIf
WEnd

Func _Search()
    PixelSearch(1268, 267, 1297, 287, 0x531C18, 10)

    If @error Then
        Return False
    Else

        Return True
    EndIf
EndFunc   ;==>_Search

Func _Second()

EndFunc

Func _Third()
    MouseClick("left",1380,265,1)
EndFunc   ;==>_Third

Share this post


Link to post
Share on other sites

Your While..WEnd will loop 6 times, each time performing 7 identical searches, so 49 PixelSearch passes all the same, there really is no need for that code.

Yes,This

If $b_Rtn OR $c_Rtn OR $d_Rtn OR $e_Rtn OR $f_Rtn OR $g_Rtn OR $h_Rtn Then
                _Second()
        $i += 1
    Elseif $b_Rtn=False AND $c_Rtn=False AND $d_Rtn=False AND $e_Rtn=False AND $f_Rtn=False AND $g_Rtn=False AND $h_Rtn=False Then ;
        _Third()
        $i=0

    EndIf

Could Be This

If $b_Rtn OR $c_Rtn OR $d_Rtn OR $e_Rtn OR $f_Rtn OR $g_Rtn OR $h_Rtn Then
                _Second()
        $i += 1
    Else
        _Third()
        $i=0

    EndIf

You are going around in circles here, explain more clearly what it is you want to accomplish.


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

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