Sign in to follow this  
Followers 0
Plxply

Variable and Random Number

4 posts in this topic

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.

Share this post


Link to post
Share on other sites



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

Share this post


Link to post
Share on other sites

#3 ·  Posted (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 by Khab

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 by Plxply

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0