Dequalityy Posted August 2, 2016 Share Posted August 2, 2016 So i have tried to figure out how to make the script send a random message, got 3 different it should choose from. So far i've tried this. $x = Random(Lol,Goto) Send($x) Exit Func Goto() Send("/goto 0", 1) Sleep(200) Send("{ENTER}", 0) EndFunc Func Lol() Send("Lol", 1) Sleep(200) Send("{ENTER}",0) EndFunc Don't know what is wrong, well i started using AutoIT my first try on programming/scripting ever. So bare with me if it's something really simple Cheers. Link to comment Share on other sites More sharing options...
SadBunny Posted August 2, 2016 Share Posted August 2, 2016 You worked with Random in your previous thread - have you not read the help file? Here's another example of what I would suggest: Local $a[4] = ["a", "c", "g", "t"] For $i = 1 To 10 ConsoleWrite($a[Random(0, UBound($a) - 1, 1)]) Next Try to understand what's going on here and translate it to your own script. Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
hajo4 Posted August 2, 2016 Share Posted August 2, 2016 29 minutes ago, Dequalityy said: So i have tried to figure out how to make the script send a random message, ... Well, try this: ConsoleWrite("## Random-Test ##" & @CRLF) For $i = 1 To 6 Local $R = Random() Select Case $R < 0.333 ConsoleWrite("Low R=" & $R & @CRLF) ;~ Send("Something{ENTER}") Case $R < 0.666 ConsoleWrite("Mid R=" & $R & @CRLF) ;~ Send("Different{ENTER}") Case Else ConsoleWrite("High R=" & $R & @CRLF) ;~ Send("Whatever{ENTER}") EndSelect Sleep(500) Next ConsoleWrite("## Done ##" & @CRLF) Exit When running this script in SciTE, watch the output-window below the source. To send text/keystrokes somewhere, you also need to have the correct window active. -HaJo Link to comment Share on other sites More sharing options...
SadBunny Posted August 2, 2016 Share Posted August 2, 2016 No, don't do that, that's bad advice (though well intended obviously ). Because in that code the distribution is uneven, the numbers are hardcoded and thus easy to get wrong (QED) and it's laborious if you want to add another option later. Use the 3rd option for the Random() function to make it return integers, and if you use an array for the send strings and UBound() like I suggested, all you would need to do is simply add an element to the array. Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
SadBunny Posted August 2, 2016 Share Posted August 2, 2016 (edited) PM by Dequalityy: 9 minutes ago, Dequalityy said: Sorry for pming u i know u told me not to, but for some freakin reason i can't reply to my topic... so i will try ask u here u can post my question & ur answer on the thread if u want to .. i just simply cant find a fkin reply button xD .. dunno whats going on with my firefox.. Local $a[4] = ["a", "c", "g", "t"] ; <- That line sets the amount of messages & messages to be sent correct me if wonrg. For $i = 1 To 10 ; <- This line says it will be done 1 to 10 times ? ConsoleWrite($a[Random(0, UBound($a) - 1, 1)]) ; <- You just simple made it write in console instead of in a active window correct? Next ; <- SKips to next part of the script Dequalityy. As for your questions in the code: The first line creates an array with 4 elements. Have you read the array manual I linked to? For starts a loop (indeed, 10 times in this case) and Next ends the loop, so all code between For and Next will be looped. It only continues to the rest of the script after all loop iterations are completed (or if it is specifically instructed to exit the loop at some point). Yes, it writes to the console, but that's not the point, what I want you to get is why it writes what it writes (10x a random letter from the array). The reply box is on the bottom of the thread. Try another browser if FF doesn't work for you (it works fine for me though). Edited August 2, 2016 by SadBunny Commented the comments in the code Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
water Posted August 2, 2016 Share Posted August 2, 2016 Dequalityy, can you please tell us which program you try to automate? Sending keystrokes is not very reliable as the user might interfere with your script. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
hajo4 Posted August 2, 2016 Share Posted August 2, 2016 4 hours ago, SadBunny said: No, don't do that, that's bad advice (though well intended obviously ). Because in that code the distribution is uneven, the numbers are hardcoded and thus easy to get wrong (QED) and it's laborious if you want to add another option later. I want to argue that with my example, it is easier to see what is going on, and you can adjust the distribution of random numbers any way you want. -HaJo 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