Pick a random action?

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
Jimmie
Newbie
Posts: 10
Joined: Tue Jan 09, 2018 3:18 pm

Pick a random action?

Post by Jimmie » Thu May 14, 2020 4:39 pm

Basically what I want to do is have 5 actions but I want macro scheduler to randomly pick one of these actions each time any idea how I can do this?

Quick example

label>start
action 1
action 2
action 3
Randomly pick one of the 3 actions and execute it.
Goto>Start

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1348
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Pick a random action?

Post by Dorian (MJT support) » Thu May 14, 2020 5:11 pm

Yes, for that we can use a combination of Random and SRT (subroutines).

Code: Select all

//Generate a random number
Random>5,Result
Let>Result=Result+1

//Call SubroutineNumber
gosub>routine%Result%

srt>routine1
  messagemodal>1
END>routine1

srt>routine2
  messagemodal>2
END>routine2

srt>routine3
  messagemodal>3
END>routine3

srt>routine4
  messagemodal>4
END>routine4

srt>routine5
  messagemodal>5
END>routine5
Yes, we have a Custom Scripting Service. Message me or go here

Jimmie
Newbie
Posts: 10
Joined: Tue Jan 09, 2018 3:18 pm

Re: Pick a random action?

Post by Jimmie » Thu May 14, 2020 5:17 pm

I sent you a private message.

Jimmie
Newbie
Posts: 10
Joined: Tue Jan 09, 2018 3:18 pm

Re: Pick a random action?

Post by Jimmie » Thu May 14, 2020 11:17 pm

I still need help with this the code above is not what I need lets say I have two images right? I want the bot to click one of the images at random each time if that makes sense?

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1348
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Pick a random action?

Post by Dorian (MJT support) » Fri May 15, 2020 9:05 am

I replied to your PMs but there's no inherent reason we need to be discussing this privately as no sensitive information is involved. So let's continue here.

The same rule applies. MessageModal was just to demonstrate how to do what you asked. That's where you put your code for each action. Use the image recognition Wizard to generate your IR code. The script at the bottom of this reply will do as you ask and can be expanded for as many images as you like.

Initially you wanted to randomize 5 actions so I went with a subroutine. Please read the helpfile section I linked to regarding Subroutines. It's explained in detail there.

If it's only two actions, this could simply be achieved with an If/Else/Endif. The result will either be 1 or 2. If it's 1, find and click image1. If it isn't, it must be 2, so find and click image2 :

Code: Select all

//Generate a random number
Random>2,Result
Let>Result=Result+1

If>result=1
  //Find and Left Click Center of 
  FindImagePos>%BMP_DIR%\image_1.bmp,SCREEN,0.7,1,XArr,YArr,NumFound1,CCOEFF
  If>NumFound1>0
    MouseMove>XArr_0,YArr_0
    LClick
  Endif
else
  //Find and Left Click Center of 
  FindImagePos>%BMP_DIR%\image_2.bmp,SCREEN,0.7,1,XArr,YArr,NumFound2,CCOEFF
  If>NumFound2>0
    MouseMove>XArr_0,YArr_0
    LClick
  Endif
endif
To cut it down even further :

Code: Select all

//Generate a random number
Random>2,Result
Let>Result=Result+1

If>result=1
  //Action 1
  MessageModal>1
else
  //Action 2
  MessageModal>2
endif

Code: Select all

//Generate a random number
Random>2,Result
Let>Result=Result+1

//Call SubroutineNumber
gosub>routine%Result%

srt>routine1
  //Find and Left Click Center of 
  FindImagePos>%BMP_DIR%\image_1.bmp,SCREEN,0.7,1,XArr,YArr,NumFound1,CCOEFF
  If>NumFound1>0
    MouseMove>XArr_0,YArr_0
    LClick
  Endif
END>routine1

srt>routine2
  //Find and Left Click Center of 
  FindImagePos>%BMP_DIR%\image_2.bmp,SCREEN,0.7,1,XArr,YArr,NumFound2,CCOEFF
  If>NumFound2>0
    MouseMove>XArr_0,YArr_0
    LClick
  Endif
END>routine2
Yes, we have a Custom Scripting Service. Message me or go here

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts