frew Posted May 16, 2009 Share Posted May 16, 2009 Hello, I'm trying to figure out how to save a randomly generated set of mouse clicks for later reuse. $y = 428 $x = Random(63, 260, 1) While 1 MouseClick("left", $x, $y, 1, 0) $x = $x + Random(12, 96, 1) If $x > 440 Then ExitLoop WEnd It generates a random pattern of clicks along the x axis. But now I wish to save the pattern of randomly generated clicks so I can use it again later. I'm trying to find a way to store each of the incremented values of x into separate new variables. Thanks for any ideas on what may be the best way to do this. frew Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 16, 2009 Moderators Share Posted May 16, 2009 frew, How about an array? ;-) M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
frew Posted May 16, 2009 Author Share Posted May 16, 2009 How about an array?Thanks Melba23.Yes I was thinking I may need to use arrays, but I'm not familiar with how to use them for something like this yet. I guess I'll experiment with them now. I was hoping for a simple little code example that would just grab the incremented x values so I could place them into a small series of MouseClicks.Thanks for the idea. I'll check into arrays some more now.frew Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted May 16, 2009 Moderators Share Posted May 16, 2009 Thanks Melba23.Yes I was thinking I may need to use arrays, but I'm not familiar with how to use them for something like this yet. I guess I'll experiment with them now. I was hoping for a simple little code example that would just grab the incremented x values so I could place them into a small series of MouseClicks.Thanks for the idea. I'll check into arrays some more now.frewhttp://www.autoitscript.com/wiki/Arrays Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 16, 2009 Moderators Share Posted May 16, 2009 frew, Do read the link in SmOke_N's post. Arrays are a fundamental part of programming. They are not difficult to understand, but can catch you out if you are not careful - like most things! ;-) M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
frew Posted May 16, 2009 Author Share Posted May 16, 2009 Looks like arrays is the way to go then. I tried stepping away from my computer...then restarting my computer, and I still don't see how to do it. Just kidding, thanks for the point in the right direction, and for the link to the Wiki about arrays. When I figure out the solution to this coding challenge I'll post what works. Now to study arrays a bit. Thank you, frew Link to comment Share on other sites More sharing options...
frew Posted May 16, 2009 Author Share Posted May 16, 2009 Until I can figure out how to use arrays well, is anybody interested in showing me how to get the following results with a loop and perhaps and array? I could build a big scripts like this one, and it would work, but I think there is a better way with looping and an array (or maybe not an array yet, but perhaps just with other coding idea I haven't thought of yet). Imagine if I had many $x values, not just the 4 below...that's where the loops and array may come in handy. $x = Random(1, 5, 1) $x1 = $x MsgBox(0, 'first $x', $x, 2) $x = $x + Random(1, 3, 1) $x2 = $x MsgBox(0, 'second $x', $x, 2) $x = $x + Random(1, 3, 1) $x3 = $x MsgBox(0, 'third $x', $x, 2) $x = $x + Random(1, 3, 1) $x4 = $x MsgBox(0, 'fourth $x', $x, 2) For $i = 1 To 2 _RepeatPattern_1() Next Func _RepeatPattern_1();the randomly generated pattern above is now available for reuse MsgBox(0, '$x1', $x1, 2) MsgBox(0, '$x2', $x2, 2) MsgBox(0, '$x3', $x3, 2) MsgBox(0, '$x4', $x4, 2) EndFunc Thanks for any ideas. frew Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted May 16, 2009 Moderators Share Posted May 16, 2009 Global $a_x[5] = [0, Random(1, 5, 1)] ; Global $a_x[5] ... We can play with elements 0 through 4 of that (5 being the index), We're going to start usage at index 1 not 0 though. Global $i_add = $a_x[1] ; Which is the Random(1, 5, 1) ; We now are going to start at the 2nd element to the end of the array elements (UBound(array) - 1) gives us that. For $i = 2 To UBound($a_x) - 1 $i_add += Random(1, 3, 1) $a_x[$i] = $i_add Next ; We've now filled our array ; No idea why you're calling that function twice, but I'll go along with it For $i = 1 To 2 _RepeatPattern_1() Next Func _RepeatPattern_1() For $i = 1 To UBound($a_x) - 1 MsgBox(64, "Info", "$a_x[" & $i & "] = " & $a_x[$i]) Next EndFunc Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Valuater Posted May 16, 2009 Share Posted May 16, 2009 (edited) Maybe.. #include <array.au3> ; for display only Global $x[5] For $i = 1 To UBound($x) - 1 $x[$i] = Random(1, 5, 1) Next For $i = 1 To 2 _RepeatPattern_1($x) Next Func _RepeatPattern_1(ByRef $array) MsgBox(4096, '$x1', $array[1], 2) MsgBox(4096, '$x2', $array[2], 2) MsgBox(4096, '$x3', $array[3], 2) MsgBox(4096, '$x4', $array[4], 2) EndFunc ;==>_RepeatPattern_1 _ArrayDisplay($x) 8) EDIT ...Just a little slow Edited May 16, 2009 by Valuater Link to comment Share on other sites More sharing options...
Bowmore Posted May 16, 2009 Share Posted May 16, 2009 There is a much easier way to do this, use SRandom() to seed Random with a constant value before generating your set of random values and Random() will return the same set of random values each time. $RandSeed = 3.5 ; chane this value to generate a different set of randome values SRandom ($RandSeed) For $i = 1 To 10 Step 1 $RandVal = Random(0,700,1) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $RandVal = ' & $RandVal & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console Next SRandom ($RandSeed) For $i = 1 To 10 Step 1 $RandVal = Random(0,700,1) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $RandVal = ' & $RandVal & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console Next "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook Link to comment Share on other sites More sharing options...
frew Posted May 16, 2009 Author Share Posted May 16, 2009 SmOke_N, Valuater, Bowmore, I greatly thank all of you for your kind help and examples. I'll need time to study these things, and then I'll post back to let you know how it goes. I think the Seeded Random way might do what I need, but the arrays is a tool that I need to get to know better. I have a music program where I can input notes randomly, but if it's a random pattern I like, I like to be able to duplicate the pattern. With quick tests it looks like the arrays ways will do it. And the Seeded Random looks like it will certainly do it too. Thanks so much for the help with this. Now I study what you've presented, and I do testing. Thanks again, frew Link to comment Share on other sites More sharing options...
frew Posted May 16, 2009 Author Share Posted May 16, 2009 (edited) Cool, this does exactly what I want. $y = 428 SRandom (12345) For $i = 1 To 4 Step 1 $x = Random(63,400,1) MsgBox(0, '', $x, 1) MouseClick("left", $x, $y, 1, 0) Next Thanks so much Bowmore for pointing me to SRandom. Basically I want to generate a set of mouse clicks that are placed randomly on the x axis, and then be able to take that randomly generated set of mouse clicks and use that set over and over if I want to. SRandom is the easiest solution. I'm still going over the array solutions too though, because they are very helpful code examples for me to learn from. Thanks again to all for the help with this. frew Edited May 16, 2009 by frew Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now