Jump to content
Sign in to follow this  
Kjello

2 whiles in same script

Recommended Posts

Kjello

When i take the other while thing off, the other one will work and vice versa, but when i put them both there like this:

While 1
If PixelGetColor(492,16) = 0xF7EFBD Then
    $bot = 0
    sleep (50)
Else
    $bot = 1
    sleep (50)
EndIf
Wend

while $bot = 1
    sleep(5)
    $coord = PixelSearch(0, 84, 800, 500, 0xFFFFFF)
    If @error Then
    Else
        sleep(5)
        MouseMove($coord[0],$coord[1],0)
        MouseClick("left",$coord[0],$coord[1],1)
    EndIf
wend

then, neither of them will work at all. No errors, the script runs but does nothing.

Is this just a basic thing what should i do? :S (it's first time i write a script)

Edited by Kjello

Share this post


Link to post
Share on other sites
FireFox

@kjello

Welcome to AutoIt forums :P

Create a function to call when needed

While 1
If Not PixelGetColor(492,16) = 0xF7EFBD Then _Bot()
sleep(50)
Wend

Func _Bot()
    sleep(10)
    $coord = PixelSearch(0, 84, 800, 500, 0xFFFFFF)
    If Not @error Then
        sleep(10)
        MouseMove($coord[0],$coord[1],0)
        MouseClick("left",$coord[0],$coord[1],1)
    EndIf
EndFunc

Not also that sleeping lower than 10milisec will be different and not preferable to be used :unsure:

Cheers, FireFox.

Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
Kjello

Thank you, but it still doesn't work! :S

Here's the full script

HotKeySet ( "{ESC}", "Terminate" )
sleep (5000)

While 1
If Not PixelGetColor(492,16) = 0xF7EFBD Then _Bot()
sleep(50)
Wend

Func _Bot()
    sleep(10)
    $coord = PixelSearch(0, 84, 800, 500, 0xFFFFFF)
    If Not @error Then
        sleep(10)
        MouseMove($coord[0],$coord[1],0)
        MouseClick("left",$coord[0],$coord[1],1)
    EndIf
EndFunc

Func Terminate ()
    Exit 0
EndFunc

Seriously WTF i even tested this with message boxes and nothing pops up. The pixel color and position is fine though.

If this is some kind of a bug, tell me does autoit do this often??

Share this post


Link to post
Share on other sites
spudw2k

If this is some kind of a bug, tell me does autoit do this often??

I seriously doubt it's a bug. Make sure you're logic IS correct.

if pixelgetcolor at x,y does not equal a light yellow color then search for whitespace, move to it and click.

Is that what you're trying to accomplish in layman's terms?

Share this post


Link to post
Share on other sites
Kjello

I seriously doubt it's a bug. Make sure you're logic IS correct.

if pixelgetcolor at x,y does not equal a light yellow color then search for whitespace, move to it and click.

Is that what you're trying to accomplish in layman's terms?

Yes. :S And when it DOES equal that light yellow colour, don't do anything.

I figured out even this doesn't work

While 1
If Not PixelGetColor(492,16) = 0xF7EFBD Then _Bot()
sleep(50)
Wend

Func _Bot ()
MsgBox (10, "asd", "asd")
EndFunc

I get no message box. Even though i'm 100% sure the pixel isn't that colour at the moment.

Ty for fast answers now i need more answers..

btw this is incredibly annoying... -.-

Could someone try this on their own? You don't even need the yellow pixel cause it's If Not. Just run this and look if u get message boxes.

Edited by Kjello

Share this post


Link to post
Share on other sites
Kjello

Ok now i tested it with other computer as exe (didn't work), i think i'll report this bug. This is fucking strange i thought this was not beta...

Share this post


Link to post
Share on other sites
SpookMeister

Test your values with something like this:

HotKeySet("{ESC}", "_Terminate")
HotKeySet("{Pause}", "_Pause")

While 1
    Sleep(100) ; usually a good idea to put this in so you dont max your cpu
    $var = PixelGetColor(492, 16)
    ToolTip("The hex color at 492,16 is" & Hex($var, 6))
WEnd

Func _Terminate()
    Exit 0
EndFunc   ;==>_Terminate

Func _Pause()
    If Not IsDeclared("isPaused") Then Global $isPaused = False
    $isPaused = Not $isPaused
    While $isPaused
        Sleep(100)
    WEnd
EndFunc   ;==>_Pause

edit - typo in code

Edited by SpookMeister

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Share this post


Link to post
Share on other sites
Kjello

Test your values with something like this:

HotKeySet("{ESC}", "_Terminate")
HotKeySet("{Pause}", "_Pause")

While 1
    Sleep(100) ; usually a good idea to put this in so you dont max your cpu
    $var = PixelGetColor(492, 16)
    ToolTip("The hex color at 492,16 is" & Hex($var, 6))
WEnd

Func _Terminate()
    Exit 0
EndFunc   ;==>_Terminate

Func _Pause()
    If Not IsDeclared("isPaused") Then Global $isPaused = False
    $isPaused = Not $isPaused
    While $isPaused
        Sleep(100)
    WEnd
EndFunc   ;==>_Pause

edit - typo in code

Is this code supposed to do anything? Cause for me it doesn't :P

Something must be totally wrong.

Edit: Oh sorry lol it does work.

No the value was NOT F7EFBD, so the code SHOULD work because my code is supposed to check if the color is not F7EFBD. So this must be a bug an di already reported it. Tell me when this gets fixed and then i will start working on my bot again :unsure:

Edited by Kjello

Share this post


Link to post
Share on other sites
SpookMeister

The tooltip should be showing you the color value that you want to base your IF statement on. (if you tried with a copy of the code before I fixed it you might want to try again.


[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Share this post


Link to post
Share on other sites
spudw2k
Kjello

Try the Not Equal operator instead.

If PixelGetColor(492,16) <> 0xF7EFBD Then _Bot()
Not working :P

This is the answer from bug track system:

No bug, just bad coding. Use the forum for coding support.

Jos

And WTF is wrong with the code??

Does AutoHotkey have pixel functions? Or any other macro program? I need this!

Fuck AutoIt...

Share this post


Link to post
Share on other sites
Kjello

Ignorance is a blessing

I must not be very ignorant because no one else has been able to solve this yet either. Not even you!

Share this post


Link to post
Share on other sites
Bert

You are not doing this right. You have to have the mindset that computers are stupid. They only do what you tell them.

First, CALM DOWN. Your life will not end just because you haven't figured out the issue. Coding is an art. And a dark art at that.

Second, you have not spelled out what window you want to check for the pixel. Do you want to search the window, client, or screen? I will assume the screen.

Third, your logic was not correct. I fixed it and tested the thing. Works fine for me. In my testing, I put in my color value for $color and values for $x and $y. I checked to see if I could get the mouse to move when the pixel was not there, and the script worked as expected. Now, I changed it so it will now work for you as you asked for it.

Opt("PixelCoordMode", 1) ;screen
Opt("MouseCoordMode", 1) ;screen
HotKeySet ( "{ESC}", "Terminate" )
sleep (5000) ;why is this here? could you use WinWaitActive instead?
$x = 492 
$v = 16
$color =  0xF7EFBD

While 1
    $getcolor = PixelGetColor($x,$v)    
    If $getcolor <> $color Then
        _Bot()
    else    
        sleep(50)
    endif
Wend

Func _Bot() 
    $left = 0
    $top = 84
    $right = 800
    $bottom = 500
    $color1 = 0xFFFFFF
    $coord = PixelSearch($left, $top, $right, $bottom, $color)
    If Not @error Then
        MouseMove($coord[0],$coord[1],0)
        sleep(100)
        MouseClick("left",$coord[0],$coord[1],1)
    EndIf
EndFunc

Func Terminate()
    Exit 0
EndFunc

Share this post


Link to post
Share on other sites
Bert

I must not be very ignorant because no one else has been able to solve this yet either. Not even you!

Now for your attitude - you need to dial it back a bit. Acting like a ungrateful jerk when others are trying to help will get you into trouble with the moderator. CHILL.

Share this post


Link to post
Share on other sites
TerarinK

I must not be very ignorant because no one else has been able to solve this yet either. Not even you!

Now, what I see is a person that just comes onto the forum for the first time trying to explain what he is doing, but you fail to explain what is it for first off. Your trying to find a color if found set the bot to false else set to true. Now, problem number one comes up you have no exit from the loop and you should have a NOT in there only declaring one which would be true because that is the only thing your looking for. The second while is if the bot is true then search a grid for FFFFFF. This is problematic due to the Else and in there onto top of the @error. This to can be rememdy by the NOT

If Not @error ThenoÝ÷ Ø  òÁ¬¬Ê£ºËgyçm Ê.±à¥ÉºÛh«"·¥j/zØ^¬zÚ-éhq«b¢|¨¹×ªÞv)ñjwrjëh×6While 1
    If Not PixelGetColor(492, 16) = 0xF7EFBD Then _Bot
    Sleep(100)
WEnd

Func _Bot()
    While 1
        $aCoord = PixelSearch(0, 84, 800, 500, 0xFFFFFF)
        If Not @error Then
            MouseClick("left", $aCoord[0], $aCoord[1])
            ExitLoop
        EndIf
    WEnd
EndFunc   ;==>_Bot

Now as what do you want out of this? I'm using your script from the beginning and thats it any error would not be because of us, but you as you had place a NOT in the wrong position, if you have any problems, you should try to remove a NOT and testing it.

I would like to know the name of the process so I can put that into the equation because I believe you are setting it to execute right off from the start and you expect it to complete in another window.


0x576520616C6C206469652C206C697665206C69666520617320696620796F75207765726520696E20746865206C617374207365636F6E642E

Share this post


Link to post
Share on other sites
spudw2k

Now for your attitude - you need to dial it back a bit. Acting like a ungrateful jerk when others are trying to help will get you into trouble with the moderator. CHILL.

Seriously, as if it couldn't possibly be the coder's fault. It must be the language. That's just silly. I blame user error. :P

Share this post


Link to post
Share on other sites
Kjello

You are not doing this right. You have to have the mindset that computers are stupid. They only do what you tell them.

First, CALM DOWN. Your life will not end just because you haven't figured out the issue. Coding is an art. And a dark art at that.

Second, you have not spelled out what window you want to check for the pixel. Do you want to search the window, client, or screen? I will assume the screen.

Third, your logic was not correct. I fixed it and tested the thing. Works fine for me. In my testing, I put in my color value for $color and values for $x and $y. I checked to see if I could get the mouse to move when the pixel was not there, and the script worked as expected. Now, I changed it so it will now work for you as you asked for it.

Opt("PixelCoordMode", 1) ;screen
Opt("MouseCoordMode", 1) ;screen
HotKeySet ( "{ESC}", "Terminate" )
sleep (5000) ;why is this here? could you use WinWaitActive instead?
$x = 492 
$v = 16
$color =  0xF7EFBD

While 1
    $getcolor = PixelGetColor($x,$v)    
    If $getcolor <> $color Then
        _Bot()
    else    
        sleep(50)
    endif
Wend

Func _Bot() 
    $left = 0
    $top = 84
    $right = 800
    $bottom = 500
    $color1 = 0xFFFFFF
    $coord = PixelSearch($left, $top, $right, $bottom, $color)
    If Not @error Then
        MouseMove($coord[0],$coord[1],0)
        sleep(100)
        MouseClick("left",$coord[0],$coord[1],1)
    EndIf
EndFunc

Func Terminate()
    Exit 0
EndFuncƒoÝŠ÷ Ûú®¢×ªº‹^©ž

Now as what do you want out of this? I'm using your script from the beginning and thats it any error would not be because of us, but you as you had place a NOT in the wrong position, if you have any problems, you should try to remove a NOT and testing it.

I would like to know the name of the process so I can put that into the equation because I believe you are setting it to execute right off from the start and you expect it to complete in another window.

But not even this works for me :S Just nothing happens...

Here's what i want to do:

In a full screen 800x600 window ("SRO_Client"), click on white pixels when the pixel 492, 16 is not #F7EFBD

Edit: Ok it works now u just frogot to put $color1 in the _Bot function (it was only $color) so it kept searching yellow pixels instead of white.

Thank you

Edited by Kjello

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.