Jump to content
Sign in to follow this  
implite

learning curve

Recommended Posts

implite

I am trying to learn this wonderful scripting language and im looking to improve this script I made at the same time. what i would like to do is make the bot wait till it sees the color then perform a function and i think im going the wrong way of doing it.

For some strange reason this kinda works but not the way as I wanted.

btw, this is my second day learning this so go easy on this noob ^_^

Opt("WinWaitDelay",100)
Opt("WinTitleMatchMode",4)
Opt("WinDetectHiddenText",1)
Opt("MouseCoordMode",0)
WinWait("Free Serf's Up - Play Now - Opera","Free Serf's Up - Pla")
If Not WinActive("Free Serf's Up - Play Now - Opera","Free Serf's Up - Pla") Then WinActivate("Free Serf's Up - Play Now - Opera","Free Serf's Up - Pla")
WinWaitActive("Free Serf's Up - Play Now - Opera","Free Serf's Up - Pla")



HotKeySet("{ESC}", "Gexit")
$mystart = 0
if $mystart = 0 then Gstart()
Func Gstart()
MouseMove(525,452)
MouseDown("left")
MouseUp("left")
sleep(500)
MouseDown("left")
MouseUp("left")
sleep(500)
MouseDown("left")
MouseUp("left")
sleep(20000)
$var = PixelGetColor(525,452)
if $var = 16777023 then MouseMove(525,452)
MouseDown("left")
MouseUp("left")
sleep(500)
MouseDown("left")
MouseUp("left")
sleep(500)
MouseDown("left")
MouseUp("left")
sleep(20000)
$var = PixelGetColor(525,452)
if $var = 16777023 then MouseMove(525,452)
MouseDown("left")
MouseUp("left")
sleep(500)
MouseDown("left")
MouseUp("left")
sleep(500)
MouseDown("left")
MouseUp("left")
sleep(20000)
$var = PixelGetColor(525,452)
if $var = 16777023 then MouseMove(522,447)
MouseDown("left")
MouseUp("left")
sleep(500)
$var = PixelGetColor(525,452)
if $var = 14869218 then MouseMove(360,541)
MouseDown("left")
MouseUp("left")
sleep(500)
$mystart = 0
if $mystart = 0 then Gstart()
EndFunc

Func Gexit()
    Exit 0
EndFunc

I think i need to use PixelSearch but I am not really sure how to even after reading Autoit help and searching the forums.

Share this post


Link to post
Share on other sites
schoel

What is it that is not working?

Share this post


Link to post
Share on other sites
schoel

Also: MouseDown followed by MouseUp can be replaced with MouseClick. MouseClick also moves the cursor if necessary.

Edit: Read the code again:

At the end of the Gstart function, you call the function again, resulting in an infinite loop. If this is your desired behaviour, I sugges you use a loop instead of recursively calling the function. There is a limit to how many times the function can be called so eventually it will quit if you don't use a loop. An infinite while loop could look like this:

While 1

[Your code here]

WEnd

Edited by schoel

Share this post


Link to post
Share on other sites
implite

instead of using sleep(20000) and repeating this 3 times in my script

MouseMove(525,452)

MouseDown("left")

MouseUp("left")

sleep(500)

MouseDown("left")

MouseUp("left")

sleep(500)

MouseDown("left")

MouseUp("left")

I would like to make it goto Func Gstart() only when it sees this color 16777023

and then when it sees this color 14869218 have it do another function

MouseMove(360,541)

MouseDown("left")

MouseUp("left")

sleep(500)

Edited by implite

Share this post


Link to post
Share on other sites
schoel

Okay, so if you actually want to check exactly 3 times, you can use a For loop:

For $variable = 0 To 2
   MouseMove(525,452)
   MouseDown("left")
   MouseUp("left")
   sleep(500)
   MouseDown("left")
   MouseUp("left")
   sleep(500)
   MouseDown("left")
   MouseUp("left")
   Here you could add a sleep if it's needed, also make sure to do whatever check you need here.
Next

Or if you actually want to do this check "forever" you can do this:

While 1
   MouseMove(525,452)
   MouseDown("left")
   MouseUp("left")
   sleep(500)
   MouseDown("left")
   MouseUp("left")
   sleep(500)
   MouseDown("left")
   MouseUp("left")
   Again make an appropiate check and if satisfied, call a function or ExitLoop
WEnd

Edit:

As mentioned above, MouseDown + MouseUp can be replaced, like this:

MouseClick("left",525,452)
   sleep(500)
   MouseClick("left")
   sleep(500)
   MouseClick("left")
Edited by schoel

Share this post


Link to post
Share on other sites
implite

Whats happening with the way I have it now is it will just skip PixelGetColor and continue down the script even if it doesnt see the color I am looking for. I dont want it to continue unless it see the color I want.

Thanks I will use the,

While 1

Wend

I think that some way I need to use PixelSearch and I want it to start looking for a color and continue looking until it finds this color 16777023 then Gstart() or if it finds this color 14869218 do a totally different function.

How do i do this? ^^

Edited by implite

Share this post


Link to post
Share on other sites
FinalVersion

Cleanup Time.

Opt("WinWaitDelay",100)
Opt("WinTitleMatchMode",4)
Opt("WinDetectHiddenText",1)
Opt("MouseCoordMode",0)
WinWait("Free Serf's Up - Play Now - Opera","Free Serf's Up - Pla")
If Not WinActive("Free Serf's Up - Play Now - Opera","Free Serf's Up - Pla") Then WinActivate("Free Serf's Up - Play Now - Opera","Free Serf's Up - Pla")
WinWaitActive("Free Serf's Up - Play Now - Opera","Free Serf's Up - Pla")


HotKeySet("{HOME}", "GStart")
HotKeySet("{ESC}", "Gexit")

while 1
    sleep(100)
WEnd


Func Gstart()
MouseMove(525,452)
MouseDown("left")
MouseUp("left")
sleep(500)
MouseDown("left")
MouseUp("left")
sleep(500)
MouseDown("left")
MouseUp("left")
sleep(20000)
$var = PixelGetColor(525,452)
if $var = 16777023 then MouseMove(525,452)
MouseDown("left")
MouseUp("left")
sleep(500)
MouseDown("left")
MouseUp("left")
sleep(500)
MouseDown("left")
MouseUp("left")
sleep(20000)
$var = PixelGetColor(525,452)
if $var = 16777023 then MouseMove(525,452)
MouseDown("left")
MouseUp("left")
sleep(500)
MouseDown("left")
MouseUp("left")
sleep(500)
MouseDown("left")
MouseUp("left")
sleep(20000)
$var = PixelGetColor(525,452)
if $var = 16777023 then MouseMove(522,447)
MouseDown("left")
MouseUp("left")
sleep(500)
$var = PixelGetColor(525,452)
if $var = 14869218 then MouseMove(360,541)
MouseDown("left")
MouseUp("left")
sleep(500)
EndFunc

Func Gexit()
    Exit 0
EndFunc

Share this post


Link to post
Share on other sites
implite

Thats cool but only restarts when I hit the home key and is not much different from what I have. I would like it to continue looping on its own but only when Pixelsearch finds 0xffff3f or 0xE2E2E2 and as you can see i have no idea how to do this.

note: I want only want these 3 functions and cut the rest. I dont think i even need sleep(20000) cause I Only want these functions called when pixelsearch finds at least one of these colors (0xffff3f or 0xE2E2E2)

0xffff3f

Func Gstart()
MouseMove(525,452)
MouseDown("left")
MouseUp("left")
sleep(500)
MouseDown("left")
MouseUp("left")
sleep(500)
MouseDown("left")
MouseUp("left")
Endfunc

I need to make this one yet:

0xE2E2E2

Func GLast()
MouseMove(360,541)
MouseDown("left")
MouseUp("left")
Endfunc

Func Gexit()
    Exit 0
EndFunc
Edited by implite

Share this post


Link to post
Share on other sites
implite

Wow, this is what I came up with so far but, I still want it to continue with out needing me to hit the home key, it would be better if I could hit the home key once and then it will loop on its own with out me hitting it again.

Opt("WinWaitDelay",100)
Opt("WinTitleMatchMode",4)
Opt("WinDetectHiddenText",1)
Opt("MouseCoordMode",0)
WinWait("Free Serf's Up - Play Now - Opera","Free Serf's Up - Pla")
If Not WinActive("Free Serf's Up - Play Now - Opera","Free Serf's Up - Pla") Then WinActivate("Free Serf's Up - Play Now - Opera","Free Serf's Up - Pla")
WinWaitActive("Free Serf's Up - Play Now - Opera","Free Serf's Up - Pla")

HotKeySet("{HOME}", "GStart")
HotKeySet("{ESC}", "Gexit")

While 1
    Wend
    Func Gstart()
   MouseMove(525,452)
   MouseDown("left")
   MouseUp("left")
   sleep(500)
   MouseDown("left")
   MouseUp("left")
   sleep(500)
   MouseDown("left")
   MouseUp("left")
   $var = PixelGetColor(525,452)
if $var = 14869218 then 
GLast()
elseif $var = 16777023 then 
Gstart()
EndIf
Endfunc


Func GLast()
MouseMove(360,541)
MouseDown("left")
MouseUp("left")
Endfunc

Func Gexit()
    Exit 0
EndFunc
Edited by implite

Share this post


Link to post
Share on other sites
Flash1212

Is this what you're looking for?

Opt("WinWaitDelay",100)
Opt("WinTitleMatchMode",4)
Opt("WinDetectHiddenText",1)
Opt("MouseCoordMode",0)

WinWait("Free Serf's Up - Play Now - Opera","Free Serf's Up - Pla")
If Not WinActive("Free Serf's Up - Play Now - Opera","Free Serf's Up - Pla") Then WinActivate("Free Serf's Up - Play Now - Opera","Free Serf's Up - Pla")
WinWaitActive("Free Serf's Up - Play Now - Opera","Free Serf's Up - Pla")

HotKeySet("{HOME}", "GStart")
HotKeySet("{ESC}", "Gexit")




Func Gstart()
   While 1
      MouseMove(525,452)
      MouseDown("left")
      MouseUp("left")
      sleep(500)
      MouseDown("left")
      MouseUp("left")
      sleep(500)
      MouseDown("left")
      MouseUp("left")
      $var = PixelGetColor(525,452)
      if $var = 14869218 then
         GLast()
      else
        ;Continue the Gstart loop
      EndIf
  Wend
Endfunc


Func GLast()
   MouseMove(360,541)
   MouseDown("left")
   MouseUp("left")
Endfunc

Func Gexit()
    Exit 0
EndFunc

**The only limit is what you believe they tell you it is**

Share this post


Link to post
Share on other sites
DavidKarner

Just update your Gstart function

Func Gstart()
   While 1
      MouseMove(525,452)
      MouseDown("left")
      MouseUp("left")
      sleep(500)
      MouseDown("left")
      MouseUp("left")
      sleep(500)
      MouseDown("left")
      MouseUp("left")
     $var = PixelGetColor(525,452)
     if $var = 14869218 then 
        GLast()
     elseif Not $var = 16777023 then 
        ExitLoop
     EndIf
   Wend
Endfunc

BTW, you might want to put a sleep(1000) or something in your main loop to keep the CPU utilization a low.

Share this post


Link to post
Share on other sites
Flash1212

Just update your Gstart function

CODE

Func Gstart()

While 1

MouseMove(525,452)

MouseDown("left")

MouseUp("left")

sleep(500)

MouseDown("left")

MouseUp("left")

sleep(500)

MouseDown("left")

MouseUp("left")

$var = PixelGetColor(525,452)

if $var = 14869218 then

GLast()

elseif Not $var = 16777023 then

ExitLoop

EndIf

Wend

Endfunc

BTW, you might want to put a sleep(1000) or something in your main loop to keep the CPU utilization a low.

I think he/she wants the script to continue indefinitely until it hits its mark or he/she ESC's the script. The Exitloop would kill the While and end the script the way it's currently written. I do agree a small sleep will be benificial. Of course that's up to how long the "color" interval is.

Edited by Flash1212

**The only limit is what you believe they tell you it is**

Share this post


Link to post
Share on other sites
picea892

Okay here are some thoughts. It's untested and I really have no idea what it's for....but hope it helps.....

Opt("WinWaitDelay",100)
Opt("WinTitleMatchMode",4)
Opt("WinDetectHiddenText",1)
Opt("MouseCoordMode",0)

WinWait("Free Serf's Up - Play Now - Opera","Free Serf's Up - Pla")
If Not WinActive("Free Serf's Up - Play Now - Opera","Free Serf's Up - Pla") Then WinActivate("Free Serf's Up - Play Now - Opera","Free Serf's Up - Pla")
WinWaitActive("Free Serf's Up - Play Now - Opera","Free Serf's Up - Pla")

HotKeySet("{HOME}", "GStart")
HotKeySet("{ESC}", "Gexit")


While 1
sleep(100)
wend

Func Gstart()
   do
       MouseMove(525,452)
       for $i=1 to 3
           sleep(500)
           MouseClick("left")
      next
      if PixelGetColor(525,452)=14869218 then $found=1
   loop until $found=1 
   GLast()
Endfunc


Func GLast()
   MouseMove(360,541)
   MouseDown("left")
   MouseUp("left")
Endfunc

Func Gexit()
    Exit 0
EndFunc
Edited by picea892

Share this post


Link to post
Share on other sites
implite

Thank you everyone for the input you gave me!

I am really making allot of progress here for only starting.

Not really sure why but this one works the best atm:

Opt("WinWaitDelay",100)
Opt("WinTitleMatchMode",4)
Opt("WinDetectHiddenText",1)
Opt("MouseCoordMode",0)
WinWait("Free Serf's Up - Play Now - Opera","Free Serf's Up - Pla")
If Not WinActive("Free Serf's Up - Play Now - Opera","Free Serf's Up - Pla") Then WinActivate("Free Serf's Up - Play Now - Opera","Free Serf's Up - Pla")
WinWaitActive("Free Serf's Up - Play Now - Opera","Free Serf's Up - Pla")

HotKeySet("{HOME}", "GStart")
HotKeySet("{ESC}", "Gexit")

while 1
    sleep(100)
WEnd

Func Gstart()
While 1
       sleep(1000)
      $var = PixelGetColor(525,452)
      if $var = 14869218 then
         GLast()
      else
         Gfirst() 
      EndIf
Wend
Endfunc

Func Gfirst()
    MouseMove(525,452)
      MouseDown("left")
      MouseUp("left")
      sleep(500)
      MouseDown("left")
      MouseUp("left")
      sleep(500)
      MouseDown("left")
      MouseUp("left")
$mystart = 0
if $mystart = 0 then Gstart()
EndFunc
    
Func GLast()
MouseMove(360,541)
MouseDown("left")
MouseUp("left")
$mystart = 0
if $mystart = 0 then Gstart()
Endfunc

Func Gexit()
    Exit 0
EndFunc

If i use pixelgetcolor like this then i get errors:

Func Gstart()
While 1
       sleep(1000)
      $var = PixelGetColor(525,452)
      if $var = 14869218 then
         GLast()
      elseif $var = 14869218 then
         Gfirst()         
      EndIf
Wend
Endfunc

Still looking for ideas on how to make this work the same way I have but Possibly without using:

$mystart = 0
if $mystart = 0 then Gstart()

To make it loop

Edited by implite

Share this post


Link to post
Share on other sites
schoel

$mystart is always 0 in your code so you don't need that check at all.

Just do this:

Func GLast()
  MouseClick(360,541)
  Gstart()
Endfunc

This code doesn't make any sense:

Func Gstart()
While 1
       sleep(1000)
      $var = PixelGetColor(525,452)
      if $var = 14869218 then
         GLast()
      elseif $var = 14869218 then
         Gfirst()         
      EndIf
Wend
Endfunc

First you check if $var is a certain number and if it's not, you do the same check again. Gfirst would never be called, if $var is that number, GLast will be called and if it is not, nothing will happen.

Share this post


Link to post
Share on other sites
implite

Func Gstart()
$mystart = 0    
    do
       sleep(2000)
      $var = PixelGetColor(525,452)
  Until $var = 14869218 or $var = 16777023
if $var = 14869218 then
         GLast()
          EndIf
if $var = 16777023 then 
         Gfirst()
         EndIf
Endfunc

This kinda works but gets stuck somewhere... any ideas how to maker this work better?

Edited by implite

Share this post


Link to post
Share on other sites
Qousio

Func Gstart()
$mystart = 0    
    do
       sleep(2000)
      $var = PixelGetColor(525,452)
  Until $var = 14869218 or $var = 16777023
if $var = 14869218 then
         GLast()
          EndIf
if $var = 16777023 then 
         Gfirst()
         EndIf
Endfunc

This kinda works but gets stuck somewhere... any ideas how to maker this work better?

#1 Check if Gstart() launches by making a msgbox.

#2 Check if PixelGetColor is retrieving any colours MsgBox( 0, "Am I getting colours?", "I got some colours ^_^" & $var )

Actually I don't like the way you made this script ;) Try using

$SearchColour1 = PixelSearch(your info here)

$SearchColour2 = PixelSearch(your info here)

If IsArray(SearchColour1) then

...... Insert random code here

EndIf

If IsArray(SearchColour2) then

...... Insert random code here

EndIf

Edited by Qousio

Share this post


Link to post
Share on other sites
implite

This is working great now.

But, I still need some help/ideas so I dont need to use:

$mystart = 0
if $mystart = 0 then Gstart()

For it to loop back to Gstart()

Other than that this is working great and soon I will be adding more stuff so the user doesn't need to hit the down arrow 8 times and also must not be using extra toolbars in opera before starting it. I am also trying to understand why PixelGetColor locks up the script if im using it more than once in other functions, Hence the learning curve... Anyways the website is http://www.grab.com/games/play-serfs-up

give it a try let me know what you think or how I can improve this. Thanks again all!!!

; This is for the game serfs up found at http://www.grab.com/games/play-serfs-up
; Hit the down arrow 8 times to get the bot lined up with all the buttons then start the script also must not be using extra toolbars in opera

Opt("WinWaitDelay",100)
Opt("WinTitleMatchMode",4)
Opt("WinDetectHiddenText",1)
Opt("MouseCoordMode",0)
WinWait("Free Serf's Up - Play Now - Opera","Free Serf's Up - Pla")
If Not WinActive("Free Serf's Up - Play Now - Opera","Free Serf's Up - Pla") Then WinActivate("Free Serf's Up - Play Now - Opera","Free Serf's Up - Pla")
WinWaitActive("Free Serf's Up - Play Now - Opera","Free Serf's Up - Pla")

MsgBox(0, "Serfs Up Bot", "hit the Home key to start the script and ESC key to stop the script ")

HotKeySet("{HOME}", "GStart")
HotKeySet("{ESC}", "Gexit")

while 1
    sleep(100)
WEnd

Func Gstart()
While 1
sleep(5000)
$coord = PixelSearch(444,421,609,481,0xffff3f,1)
    If Not @error Then
        mouseclick("left" ,$coord[0], $coord[1], 2, 0) 
        sleep(500)
      MouseDown("left")
      MouseUp("left")
      sleep(500)
      MouseDown("left")
      MouseUp("left")
  EndIf
  if PixelGetColor(525,452) = 14869218 then
      GLast()
      EndIf
  Wend
Endfunc


Func GLast()
MouseMove(360,541)
MouseDown("left")
MouseUp("left")
MouseMove(525,452)
MouseDown("left")
MouseUp("left")
sleep(500)
MouseDown("left")
MouseUp("left")
$mystart = 0
if $mystart = 0 then Gstart()
Endfunc

Func Gexit()
    MsgBox(0, "Serfs Up Bot", "Script has ended")
    Exit 0
EndFunc
Edited by implite

Share this post


Link to post
Share on other sites
implite

If Not @Error?
yeah im a noob... Dont know why but it doesn't give me an error, even though its in there.

Also when Take this out like this:

Func Gstart()
While 1
sleep(5000)
$coord = PixelSearch(444,421,609,481,0xffff3f,1)
        mouseclick("left" ,$coord[0], $coord[1], 2, 0) 
        sleep(500)
      MouseDown("left")
      MouseUp("left")
      sleep(500)
      MouseDown("left")
      MouseUp("left")
  if PixelGetColor(525,452) = 14869218 then
      GLast()
      EndIf
  Wend
Endfunc

I get this error:

Posted Image

This all is a learning process. I think you all where here as where I am at one point before you got Godly

Share the love, lol...

Edited by implite

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  

×