AutoHotkey Community

It is currently May 26th, 2012, 8:50 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 13 posts ] 
Author Message
PostPosted: June 22nd, 2009, 6:39 am 
Offline

Joined: November 22nd, 2008, 9:52 pm
Posts: 44
Code:
Random(min,max) {

  Random, res, % min, % max
  Return res

}

#4::
SetMouseDelay, % Random(50,65)         ;#4, loop4, F4, FishBCheck, F7, repeat loop4 >
WinGetPos,,, x, y, A
GoSub, loop4
Return

Loop4:
Sleep, % Random(50,100)
SetMouseDelay, % Random(50,65)
GoSub, prelogout
GoSub, Huml
GoSub, F4
Return

F4:
Sleep, % Random(200,400)
SetKeyDelay, 4, 6,
Send {F4}
GoSub, prelogout
PixelSearch, Px, Py, 895, 320, 920, 345, 0x202876, 3, Fast
if ErrorLevel
   GoSub, F4
else
   Sleep, % Random(1500,1700)
GoSub FishBCheck
Return

FishBCheck:
Sleep, % Random(200,300)
GoSub, prelogout
PixelSearch, Px, Py, 836, 400, 852, 412, 0x7F6663, 3, Fast
if ErrorLevel
   GoSub, FishBCheck
else
   GoSub, I21L2
GoSub, F7
Return

F7:
Sleep, % Random(200,400)
GoSub, prelogout
SetKeyDelay, 4, 6,
Send {F7}
PixelSearch, Px, Py, 995, 320, 1020, 345, 0x1E2875, 3, Fast
if ErrorLevel
   GoSub, F7
else
   GoSub, loop4
Return

PreLogout:
PixelSearch, Px, Py, 995, 320, 1020, 345, 0x337095, 3, Fast
if ErrorLevel
   GoSub, logout
else
   sleep, 1
Return

Logout:
MouseClick, Left , % Random(1010,1020), % Random(150,165)
Sleep, % Random(500,2000)
MouseClick, Left , % Random(840,970), % Random(510,535)
Sleep, % Random(60000,120000)
Return

HumL:
MouseClick, Left , % Random(826,841), % Random(396,414)
Return

I21L2:
Sleep, % Random(150,250)
MouseClick, Left , % Random(836,852), % Random(400,412)
Return



Explanation what the script does.
Its a runescape humidify script. In short - it clicks on the 1st spot, after which it clicks F4 until the colour1 changes. It waits until the colour2 changes again and it clicks on the 2nd spot. It clicks F7 until the colour3 changes. During the script if colour4 changes it logs off the acc. and shuts down the pc.

Now the strange thing is - it runs for ~1000 casts of humidify (~ 1 hour and 10 minutes) after which the script/autohotkey crashes ... any idea why does this happen ?


Last edited by me10c on June 22nd, 2009, 9:19 pm, edited 3 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 22nd, 2009, 7:57 am 
Offline

Joined: March 27th, 2009, 10:48 pm
Posts: 71
Are you shure it crashes? or just ends.

Try putting #Persistent at the top of you script.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 22nd, 2009, 8:49 am 
BF2 Player wrote:
Are you shure it crashes? or just ends.

Try putting #Persistent at the top of you script.

Incorrect! The script is already persistent due to the presence of a hotkey.

Quote:
A script that is not persistent and that lacks hotkeys, hotstrings, OnMessage, and GUI will terminate after the auto-execute section has completed. Otherwise, it will stay running in an idle state, responding to events such as hotkeys, hotstrings, GUI events, custom menu items, and timers.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: June 22nd, 2009, 10:33 am 
Offline

Joined: November 22nd, 2008, 9:52 pm
Posts: 44
it doesnt finishes for sure .. its kind of a loop as you can see.
it crashes and I am sure about it "windows have found a problem and the program needs to be closed" or something like that (I am too lazy to check the acutal message but you get the idea).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 22nd, 2009, 2:57 pm 
Quote:
I am too lazy to check the acutal message

i am to lazy to actually help you.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: June 22nd, 2009, 3:14 pm 
Offline

Joined: November 22nd, 2008, 9:52 pm
Posts: 44
Yeaaah I am sure most of the ppl actually got the idea which message I was talking about, but then again I will post the exact message tomarow (it will take some time to get it again)
I dont see where is the hard part about "Windows has found a problem with this file" and AHK has crushed ... but anyways ... yeah tnx


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 22nd, 2009, 3:49 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
me10c wrote:
Yeaaah I am sure most of the ppl actually got the idea which message I was talking about...


No offense, but it doesn't matter if we've "got the idea," the error details supplied when the crash occurs are more important than anyone here's general idea about the error message. That aside, you also didn't post your entire code; even if those code portions don't appear to be relevant you should post them anyway since you may have a problem with those that someone here can identify.

FYI, instead of repeatedly using the Random command in your script you can wrap the command into a function and trim a bit of your code:

Code:
Random(min,max) {

  Random, res, % min, % max
  return res

}


#4::  ;#4, loop4, F4, FishBCheck, F7, repeat loop4 >
SetMouseDelay, % Random(50,65) ; forces expression mode so the function can be processed
WinGetPos,,, x, y, A
GoSub, loop4
return

loop4:
Sleep, % Random(50,100)
SetMouseDelay, % Random(50,65)
PixelSearch, Px, Py, 995, 320, 1020, 345, 0x337095, 3, Fast
if ErrorLevel
   GoSub, logout
else
   GoSub, Huml
GoSub, F4
return

F4:
SetKeyDelay, 2, 8
Sleep, % Random(200,400)
Send {F4}
PixelSearch, Px, Py, 995, 320, 1020, 345, 0x337095, 3, Fast
if ErrorLevel
   GoSub, logout
else
   sleep, 1
PixelSearch, Px, Py, 895, 320, 920, 345, 0x202876, 3, Fast
if ErrorLevel
   GoSub, F4
else
   sleep, 1500
GoSub FishBCheck
return

FishBCheck:
Sleep, % Random(200,300)
PixelSearch, Px, Py, 995, 320, 1020, 345, 0x337095, 3, Fast
if ErrorLevel
   GoSub, logout
else
   sleep, 1
PixelSearch, Px, Py, 836, 400, 852, 412, 0x7F6663, 3, Fast
if ErrorLevel
   GoSub, FishBCheck
else
   GoSub, i21l2
GoSub, F7
return

F7:
Random, Rand, 200, 400
Sleep, %Rand%
SetKeyDelay, 2, 8,
Send {F7}
PixelSearch, Px, Py, 995, 320, 1020, 345, 0x1E2875, 3, Fast
if ErrorLevel
   GoSub, F7
else
   GoSub, loop4
return

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 22nd, 2009, 4:13 pm 
Offline

Joined: November 22nd, 2008, 9:52 pm
Posts: 44
Now when you mention it ...
Those parts of the code are scattered around the file itself ...
Anyways they were just random clicks
As I said I thought that the message is standart .. I will try to "crash" it till tomarow (well 12 hours till then by my clock :lol: )

I am not sure but it might be all those colour checks .. I think it crashes from them (overloaded or something :? ?).

EDIT:
I assume I can use
Code:
Random(min,max) {

  Random, res, % min, % max
  return res

}


for multiple scripts in the same file ? (I mean :

Code:
Random(min,max) {

  Random, res, % min, % max
  return res

}

#1::
Sleep, % Random(50,100)
return

#2::
Sleep, % Random(50,200)

#3::
Sleep, % Random(50,400)

etc etc


EDIT2:
is there something similiar for
Random, Xpos, x1, x2
Random, Ypos, y1, y2
MouseClick, Left , Xpos, Ypos

I have like 50 of those :lol:
In other words is there a way to make it 1 lined like the PixelSearch coordinates

and is there a way to make the IF 1 lined
Code:
   Random, Rand, 1, 4
   IF(Rand = 1)
   {
   GoSub, 1
   }
   IF(Rand = 2)
   {
   GoSub, 2
   }
   IF(Rand = 3)
   {
   GoSub,3
   }

In other words to make it something like this
Code:
IF(Rand =1), { GoSub, 1 }

I have a lot of those 2 ... (while we are at it I can at least make my code ... smaller while trying to figure out while does it crash :lol: )


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 22nd, 2009, 4:34 pm 
Offline

Joined: August 13th, 2006, 6:45 am
Posts: 355
Location: Germany
You may get indefinite loops. You use
Quote:
gosub F4 in F4:
gosub F7 in F7:
gosub FishBCheck in FishBCheck:

I think, this may crash windows.

Hubert


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 22nd, 2009, 4:37 pm 
Offline

Joined: November 22nd, 2008, 9:52 pm
Posts: 44
Yeah I made those on purpose ...
I need it to click when the colour apears and I dont know another way

basicly when the sub starts and if it doesnt find the colour the sub starts again, and it does that until the colour is found ... (it usually does that 1 or 2 times , so there is no chance of a big loop)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 22nd, 2009, 4:51 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
me10c wrote:
I assume I can use
Code:
Random(min,max) {

  Random, res, % min, % max
  return res

}


for multiple scripts in the same file?


Yes, as long as your working script has a reference to the function any hotkeys/applicable commands can access it. In your second example you would use the function like this to create a one-line command for MouseClick:

Code:
MouseClick, Left , % Random(x1,x2), % Random(y1,y2)


You can also change the if/else format as well:

Code:
If Random(1,4) = 1
  GoSub, 1
else If Random(1,4) = 2
  GoSub, 2
else If Random(1,4) = 3
  GoSub,3

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Last edited by sinkfaze on June 22nd, 2009, 5:10 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 22nd, 2009, 5:09 pm 
Offline

Joined: November 22nd, 2008, 9:52 pm
Posts: 44
the last thing that remains is
what is the code for "when this colour apears do that"
so I can remove the loops ...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 22nd, 2009, 5:38 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
me10c wrote:
what is the code for "when this colour appears do that"
so I can remove the loops ...


Perhaps a PixelSearch function would suffice (untested):

Code:
PixelSearch(x1,y1,x2,y2,cid,var="",mode="") { ; 'cid' is ColorID and 'var' is Variation

  global Px
  global Py

  PixelSearch, Px, Py, % x1, % y1, % x2, % y2, % cid, % var, % mode
  if ErrorLevel
    return true

}

loop4:
Sleep, % Random(50,100)
SetMouseDelay, % Random(50,65)
if PixelSearch(995,320,1020,345,0x337095,3,"Fast") ; checks if the functions returns true for 'ErrorLevel' (literal text must be in quotation marks)
   GoSub, logout
else
   GoSub, Huml
GoSub, F4
return

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, coinman, Leef_me, oldbrother and 59 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group