 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Free Guest
|
Posted: Sat Mar 15, 2008 6:12 pm Post subject: Trying to undertsnad Random |
|
|
Hi scripters,
After searching for over an hour i did not find my solution. It's actually very simple. I will explain in the example script. (I'm newbie to ahk btw)
What i would like to achieve is : Every new MouseClick line i would like to have a 'new' chosen random number. In the example it will always use the first random value and keep on using it in every following line.
| Code: |
Random, random50,-50,50 ; click -50 to +50 pixels
WinActivate, Paint
MouseClick,left, % (500 + random50), % (500 + random50)
Sleep, 3000
MouseClick,left, % (500 + random50), % (500 + random50)
Sleep, 3000
MouseClick,left, % (500 + random50), % (500 + random50)
Sleep, 3000
|
Like i said. This is example code.
I hope i make myself clear. Thanks for looking at this. |
|
| Back to top |
|
 |
Freestyler
Joined: 17 Nov 2007 Posts: 5
|
Posted: Sat Mar 15, 2008 6:41 pm Post subject: |
|
|
pfew. Logged in now..
I think i understand random.. But did not understand loop!
I will try now. If any guru can show me little loop example of my random issue i would be a very happy guy.
Free |
|
| Back to top |
|
 |
Wouther
Joined: 01 May 2007 Posts: 78 Location: The Netherlands
|
Posted: Sat Mar 15, 2008 9:01 pm Post subject: |
|
|
In your code you only use Random once and that is where you generate the random number. You do not use Random again and therefore you use the same number over and over. Try something like this:
| Code: | WinActivate, Paint
Loop
{
Random, random50,-50,50 ; click -50 to +50 pixels
MouseClick,left, % (500 + random50), % (500 + random50)
Sleep, 3000
} | ...or if you do not want the loop and just three times, as in your example, remove it.  _________________ Printing css/html-formatted text |
|
| Back to top |
|
 |
Freestyler
Joined: 17 Nov 2007 Posts: 5
|
Posted: Sat Mar 15, 2008 11:40 pm Post subject: |
|
|
Hi. Thanks for the reply.
I was hoping to use the random on several different coordinates. In the example code you showed it is defined per command. If after 5 seconds another different coord is clicked and i again want it to be +-50 then i would have to re-type this.
I understand how it will work but am looking for a way to use it on different locations in my code.
TY for your kind help btw! |
|
| Back to top |
|
 |
Lurker1457
Joined: 10 Mar 2008 Posts: 11
|
Posted: Sun Mar 16, 2008 12:00 am Post subject: |
|
|
If you prefer it the function way... | Code: | WinActivate, Paint
MouseClick,left, % (500 + random(50)), % (500 + random(50))
Sleep, 3000
MouseClick,left, % (500 + random(50)), % (500 + random(50))
Sleep, 3000
MouseClick,left, % (500 + random(50)), % (500 + random(50))
Sleep, 3000
; unction definitions live at the bottom of a script...
Random( number )
{
Random, outnum, % 0-number, % number
return % outnum
} |
|
|
| Back to top |
|
 |
Freestyler
Joined: 17 Nov 2007 Posts: 5
|
Posted: Sun Mar 16, 2008 9:23 am Post subject: |
|
|
Thanks a lot! I will try it asap.
Since you tell me that functions live in the bottom of a script. How can i find out this knowledge?
I have read the ahk manual and it seems that this kind of info is not mentioned. Long long time ago i tried VB. Can i read a VB course book and use that knowledge in ahk scripting? TY in advance.
Great help, Great community. |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 2540 Location: Australia, Qld
|
Posted: Sun Mar 16, 2008 1:04 pm Post subject: |
|
|
| Script execution automatically skips over function bodies, so it doesn't matter where in the script they are (as long as they aren't somewhere invalid like inside another function.) It is generally more readable and perhaps more maintainable to at least put the functions after the auto-execute section, though. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|