Sign in to follow this  
Followers 0
scriptingishard2

Need help with this script.

7 posts in this topic

#1 ·  Posted (edited)

I'm a total newbie using autoit. I was wondering if anyone could tell me how to fix this script so it functions the way I want it to.

What I want this script to do is, continue in an infinite loop. What I want it to do is, look at a pixel I specify and if that pixel is a certain color I want it to do 1 left click on an x y corodinate that I specify. If that pixel is not that one particular color I want it to do nothing but move on to the next statement, and the next statement is the same kind of thing.

Here is what I have so far, when I run this, it doesn't continue it just appears for 1/2 second in the tray and disappears, so obviously it's not going in a continual loop. That isn't the only thing, even when the pixel is the specified color it doesn't produce a click at all. I know I may have things in there that don't belong or I'm missing things I would need or the syntax is wrong. I would appreciate your help in fixing it to work properly.

Func GetAction()

$color = PixelGetColor (1470, 56);

if $color = 20000 then

MouseClick ( "left" [, 250, 480 [, 1 [, 10 ]]] );

return 1;

endif

$color = PixelGetColor (1470, 67);

if $color = 70000 then

MouseClick ( "left" [, 419, 574 [, 1 [, 10 ]]] );

return 2;

endif

$color = PixelGetColor (1470, 78);

if $color = 80000 then

MouseClick ( "left" [, 567, 476 [, 1 [, 10 ]]] );

return 3;

endif

$color = PixelGetColor (1470, 88);

if $color = 40000 then

MouseClick ( "left" [, 567, 476 [, 1 [, 10 ]]] );

return 4;

endif

return 1;

EndFunc

I see that people have looked at my thread yet no one has posted anything. Let me know if you need any more information, or if you just wouldn't know how to do what I'm looking for this script to do, that way I at least know where you guys are that are reading this post, thanks. If you would like a drawing of what I'm talking about I could make one.

Edited by scriptingishard2

Share this post


Link to post
Share on other sites



I figured out some things, I fixed some of the script so that it now appears to do what it's supposed to do for the most part, now the only part I need help with is how to get it into an infinite loop.

How do I set it up so my script just keeps running over and over without stopping?

Share this post


Link to post
Share on other sites

maybe like this

; Press Esc to terminate script

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


;;;; Body of program would go here;;;;
While 1
    GetAction()
    Sleep(10)
WEnd
;;;;;;;;

Func Terminate()
    Exit 0
EndFunc

Func GetAction() 
; Your
; Script
; Here

EndFunc

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Nope that didn't work.

What that did is, if it doesn't find any of the pixel colors it was looking for, it will stay in the tray but even if those colors come up, it won't do anything, it just stays in the tray until you exit it.

If you run it and it does find the one of the colors it's looking for right away then it will do it's one action and then it will quit, and I don't want it to do that, even if it finds the color and does the action I want it to stay running so it will continue to work.

This is what it looks like with the code you suggested added.

; Press Esc to terminate script

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

$color = PixelGetColor( 1470 , 56 )

if $color = 40000 then

MouseClick("left", 250, 480, 1, 10)

return 1;

endif

$color = PixelGetColor( 1470 , 67 )

if $color = 50000 then

MouseClick("left", 429, 477, 1, 10)

return 2;

endif

$color = PixelGetColor( 1470, 78 )

if $color = 60000 then

MouseClick("left", 567, 476, 1, 10)

return 3;

endif

$color = PixelGetColor ( 1470, 88 )

if $color = 70000 then

MouseClick("left", 567, 476, 1, 10)

return 4;

endif

While 1

GetAction()

Sleep(10)

WEnd

;;;;;;;;

Func Terminate()

Exit 0

EndFunc

Func GetAction()

; Your

; Script

; Here

EndFunc

Now it could be that I have some code in there that is telling it to end, if there is some replacement code or something else I can do to keep it running though the script that would be cool.

Thanks for your reply's hope to keep hearing from you guys.

Edited by scriptingishard2

Share this post


Link to post
Share on other sites

what did you do?

it should be

HotKeySet("{ESC}", "Terminate")
While 1
$a = GetAction()
;msgbox(0, "Returnvalue", $a)
Sleep(10)
WEnd
;;;;;;;;

Func Terminate()
Exit 0
EndFunc

Func GetAction() 
$color = PixelGetColor( 1470 , 56 )
if $color = 40000 then 
MouseClick("left", 250, 480, 1, 10)
return 1; 
endif 
$color = PixelGetColor( 1470 , 67 ) 
if $color = 50000 then 
MouseClick("left", 429, 477, 1, 10)
return 2; 
endif 
$color = PixelGetColor( 1470, 78 ) 
if $color = 60000 then 
MouseClick("left", 567, 476, 1, 10)
return 3; 
endif 
$color = PixelGetColor ( 1470, 88 ) 
if $color = 70000 then 
MouseClick("left", 567, 476, 1, 10)
return 4; 
endif
EndFunc

for what do you need the return-values?

Share this post


Link to post
Share on other sites

Thanks, that works. I'm such a noob I don't even know why the return values are there. I guess the only other thing is, using your way of making it go into a loop, is there a way to add pauses between each action? Like 2 seconds for each using the sleep command? So that I could move the mouse for 2 seconds before it goes to the next function?

Share this post


Link to post
Share on other sites

sure there is:

HotKeySet("{ESC}", "Terminate")
hotkeyset("{pause}", "Pausemefast")
While 1
GetAction()
Sleep(2000);here is your sleep - just increase if you need more time
WEnd
;;;;;;;;

Func Terminate()
Exit 0
EndFunc

Func GetAction() 
$color = PixelGetColor( 1470 , 56 )
if $color = 40000 then 
MouseClick("left", 250, 480, 1, 10)
endif 
$color = PixelGetColor( 1470 , 67 ) 
if $color = 50000 then 
MouseClick("left", 429, 477, 1, 10)
endif 
$color = PixelGetColor( 1470, 78 ) 
if $color = 60000 then 
MouseClick("left", 567, 476, 1, 10)
endif 
$color = PixelGetColor ( 1470, 88 ) 
if $color = 70000 then 
MouseClick("left", 567, 476, 1, 10)
endif
EndFunc

func Pausemefast()
sleep (10000)
endfunc

if you hit {pause} you get an additional sleep of 10 secs

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