Plxply Posted May 7, 2009 Share Posted May 7, 2009 Hello, I am currently attempting to make a script in AutoIT (one of my first ones), that would generate a random number directly after a variable. I have of course defined the variables before going from $command1 to $command20. I am simply attempting to run the following line: Send($command(Random(1,20)); The outcome I am trying to achieve is for it to choose a number between 1 and 20, and place it after $command so it will for example run Send($command6); But unfortunately each time it is erroring out at the line of code I have previously mentioned, I have Googled around and have also searched on this forum but have been unable to find the answer I am looking for. I hoping with the experience people carry on this forum they would be able to help me. Link to comment Share on other sites More sharing options...
WideBoyDixon Posted May 7, 2009 Share Posted May 7, 2009 Try: Global $aCommand[20] $aCommand[0] = {Whataever you were previously setting up as $command1} ... $aCommand[19] = {Whataever you were previously setting up as $command20}oÝ÷ Ù8^*.q©ìjeÉ«¢+ÙM¹ ÀÌØí ½µµ¹mI¹½´ Ä°ÈÀ°Ä¤´Åt¤ WBD [center]Wide by name, Wide by nature and Wide by girth[u]Scripts[/u]{Hot Folders} {Screen Calipers} {Screen Crosshairs} {Cross-Process Subclassing} {GDI+ Clock} {ASCII Art Signatures}{Another GDI+ Clock} {Desktop Goldfish} {Game of Life} {3D Pie Chart} {Stock Tracker}[u]UDFs[/u]{_FileReplaceText} {_ArrayCompare} {_ToBase}~ My Scripts On Google Code ~[/center] Link to comment Share on other sites More sharing options...
Khab Posted May 7, 2009 Share Posted May 7, 2009 (edited) I take it $command1 through $command20 are strings of keypresses for Send to simulate? To be honest I've never tried to use a variable variable name in AutoIt, one way that is a bit longer that I can think of to make it work would be $randomNumber = Random(1,20) if $randomNumber == 1 Then Send($command1) elseif $randomNumber == 2 Then Send($command2) elseif .. .. elseif $randomNumber == 20 Then Send($command20) endif Though I'm sure one of the more experienced users here will have a simpler / more elegant solution. Edit: Beaten ^^ Good idea WBD, an array would let you do this better than my suggestion. Edited May 7, 2009 by Khab Link to comment Share on other sites More sharing options...
Plxply Posted May 7, 2009 Author Share Posted May 7, 2009 (edited) Try: Global $aCommand[20] $aCommand[0] = {Whataever you were previously setting up as $command1} ... $aCommand[19] = {Whataever you were previously setting up as $command20}oÝ÷ Ù8^*.q©ìjeÉ«¢+ÙM¹ ÀÌØí ½µµ¹mI¹½´ Ä°ÈÀ°Ä¤´Åt¤ WBD Thanks for the suggestion WBD it worked extremely well for me, and also Khab thanks also for your ideas I would of tried yours also if WBD did not reply so quickly Edited May 7, 2009 by Plxply 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