Jump to content
Macro Express Forums

Selecting Something Randomly.


Recommended Posts

Alright, let me explain what I'd like to do.


I have four locations on the window the mouse needs to move to. I want it to choose one of these positions at random.


I can figure out the rest of the script once I know how to choose something at random.


I'm guessing I need to use a variable, logic, or something to that effect, but I don't know how to go about doing this. I wrote a couple other scripts before, but they were simple in comparison, being only tons of pointing and clicking, with a repeat.


Can someone help me on how to go about this?




Link to comment
Share on other sites

Use the "set integer variable" command with "set a random value" option.


Set the maximum random value to 3. This will select a random number 0 to 3.


You can then use if/then or switch/case logic on the variable value= 0,1,2, or 3 to move the mouse to one of your four locations.

Link to comment
Share on other sites

Thanks! Lemme cook that up and test it out, and I'll get right back to you.




Ok, I'm lost. I put in "Variable Set Integer %N1% with a Random Number," but I don't know where to go from here.. I don't understand how to set up the rest... or if I even have this command in the right spot.


Also, how will it assign the numbers, 0, 1, 2, and 3, to my mouse positions...?


This is an area outside my realm of comprehension... I don't understand.


<edit #2>


Alright, I think I figured it out playing around with it for a long while. Does this look nominal for my switch/case command? Is it possible to make it "better?"




<REM2:Bookmark B>
<REM2:Bookmark C>
<REM2:Bookmark D>
<REM2:Bookmark E>


Link to comment
Share on other sites

Yes, that's the right way to use the switch/case logic.


There is only one thing I would suggest to make this "better", which may or may not work in your application. Do you really need to use the mouse movement and a mouse click?


Wherever possible, I use 'text type' with the type text normally option to issue commands to applications. So if there is an item that can be accessed with a mouse click or with a keyboard shortcut (eg, control-letter or alt-letter followed by another letter, or alt-letter followed by several down arrows followed by enter), I always opt for using text type with the keyboard shortcut.


That way, the macro will always work regardless of monitor size, where things are arranged on the screen, etc.


But of course, there are times where there's no keyboard shortcut available and you have to use mouse clicks.

Link to comment
Share on other sites

Ah, thanks for your input. Yes, I try to use keyboard shortcuts and other shortcuts to avoid using the mouse where possible, but for this program, unfortunately there are very few, and no controls to speak of either -- making the mouse the primary tool for getting around in this app. ;)


I greatly appreciate the help, thank you again.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...