Jump to content
Macro Express Forums

Randomizing a 'playlist' of macros


Recommended Posts

I have created a series of 41 short macros which are all nearly identical. They all do the same functions but pull up different files to work with. For anyone interested in what kind of files these are, they are routines created in software designed to control animatronic robots for a Halloween display. each routine is a different length and has different content. I made the individual macros that first calculate how long the routine runs, then opens the software and starts it while counting down a timer, then 10 seconds after the timer runs out (Which was set to the length of the routine) it would unload the routine and shut down the software.

 

I wrote a second simple routine that basically just plays each of the smaller routines in a row, waiting for each routine to complete before starting the next one, so that I could leave the display running unattended for long periods of time.

 

What I want to do, is to treat the small macros like a playlist as though it were a music program. It would load up all 41 macros, and execute them in a random order until they were all played and then repeat. It would repeat forever until I shut it down.

 

The rules would be that:

1. It would only play each macro once within a rotation before reloading them all to start again.

2. The order would be random, without the possibility of repeating a macro within that rotation.

3. When repeating the rotation, it would again be random and not repeat the same pattern as before, and

4. It would never play the same file for a second time, if that file had been played within the last 10 files. (For example, if the first rotation played all the files, and ended with file 41, the next rotation could not play file 41 again until 10 other files had been played first. If the random pattern chose macro 41, and it had been less that 10 macros since it was played previously, it would recalculate and choose the next random number instead, assuming that it, too had not been played in the last 10 plays. basically it would have to keep track continuously of the last 10 files played in an array that would add a file every play and drop one off the end on every play always holding the last 10 and would prohibit playing any file if it was still on the list, and instead choose another file randomly.

 

Because this is random, it is theoretically possible that could continuously keep choosing files that are on the list, so I suppose that after the list is created, it should only consider files that are not on the list before assigning a random number and making a choice, making anything in the array unavailable until it drops off.

 

I have not found any way to even select macros to run within a macro in a random manner, even without the rules.

 

can anyone help me create this?

 

Thank you,

Bob

 

 

Link to comment
Share on other sites

My first thought would be to put the names of the macros in a string array variable and then create an integer array variable of the same size with random numbers in it. Loop from the beginning to the end of the integer array and grab the integer value and use it as an index into the string array.

 

This doesn't do everything you specify but it may get you started and you could adjust as needed.

Variable Set Integer %ArrayElements% to 40
Variable Set String %MacroArray% to ""
 
Variable Set String %MacroArray[1]% to "MacroName1"
Variable Set String %MacroArray[2]% to "MacroName2"
Variable Set String %MacroArray[3]% to "MacroName3"
//               .
//               .
//               .
Variable Set String %MacroArray[40]% to "MacroName40"

Repeat Start (Repeat %ArrayElements% times)
  Variable Set Integer %IdxArray[1]% to 0
  Variable Set Integer %IdxArray[%Idx%]% to a random value between 1 and %ArrayElements%
End Repeat
 
Repeat Start (Repeat %ArrayElements% times)
  Macro Run: %MacroArray[%Idx%]%
End Repeat

You could also put the names of the macros in a file and use something like the Text File Begin/End Process commands to load them into the MacroArray variable.

Link to comment
Share on other sites

Thank you for the reply. I am pretty good with using the Macro Express Pro interface with the choices they give you, but have never written custom scripts. I will play around with it and see how to do that, and try to plug this format into what I have. To keep it simple, the macro names are already just the numbers. The first macro is names 01 and the last is named 41. so the numbers and the names can actually be the same. I don't know if that's good or will just cause confusion.

 

I will see how far I get.

 

Once I get something like this t run, I will be looking for the rest of the functionality as well, but one step at a time.

Link to comment
Share on other sites

I can think of a smart way to do this but given you can do thousands of guesses a second I think I'd keep it simple. For the end of it I would put each Macro Run command in a Select/Case block and use an integer variable as an index. This way whatever logic we make before this has an easy way to lookup when we pick our integer value. Now back to the beginning. I would use a random number generator to start. Then next the levels of logic, each testing for one of your criterion. I would try making an array of integers to track how many times ago each macro was played. Start with a huge number like 99. Use the random number to consider one of these values. If the number in this tracking list is greater than 10 then move forward. If it's not keep generating random numbers until you do. Now if it is greater than 10, set the number to zero. Then go though each element of the array and increase it by one. And then of course this would all be in a loop of 41 after which you would reset all the values and start over again. The only criteria it would not technically satisfy is #3 but the odds of repeating 41 selections identically back to back is astronomical.

 

Edit: Oh, and at the end of each of the random selection per criterion would then be used as the pointer in the select case.

Link to comment
Share on other sites

Try this :

<COMMENT Value="################" _FORE="004080FF" _BACK="00000040"/>
<COMMENT Value="Run a random macro, unique time." _FORE="004080FF" _BACK="00000040"/>
<COMMENT Value="################" _FORE="004080FF" _BACK="00000040"/>
<COMMENT Value="################" _FORE="0000FFFF" _BACK="00004080"/>
<COMMENT Value="Options." _FORE="0000FFFF" _BACK="00004080"/>
<COMMENT Value="################" _FORE="0000FFFF" _BACK="00004080"/>
<COMMENT Value="Max number it can be." _FORE="0000FFFF" _BACK="00004080"/>
<VARIABLE SET INTEGER Option="\x00" Destination="%N[3]%" Value="40" _FORE="00C0C0C0" _BACK="00004080"/>
<COMMENT Value="Number of randoms numbers to generate = number of macros to run." _FORE="0000FFFF" _BACK="00004080"/>
<VARIABLE SET INTEGER Option="\x00" Destination="%N[5]%" Value="40" _FORE="00C0C0C0" _BACK="00004080"/>
<COMMENT Value="2 digits." _FORE="0000FFFF" _BACK="00004080"/>
<VARIABLE SET INTEGER Option="\x00" Destination="%N[4]%" Value="2" _FORE="00C0C0C0" _BACK="00004080"/>
<COMMENT _BACK="00C0C0C0"/>
<REPEAT UNTIL Variable="%N[1]%" Condition="\x04" Value="%N[5]%" _BACK="00C0C0C0"/>
<VARIABLE SET INTEGER Option="\x05" Destination="%N[2]%" Minimum="0" Maximum="%N[3]%" _BACK="00C0C0C0"/>
<VARIABLE SET STRING Option="\x00" Destination="%T[2]%" Value="%N[2]%" NoEmbeddedVars="FALSE" _BACK="00C0C0C0"/>
<VARIABLE MODIFY STRING Option="\x0D" Destination="%T[2]%" Width="%N[4]%" _BACK="00C0C0C0"/>
<VARIABLE MODIFY STRING Option="\x0F" Destination="%T[2]%" ToReplace=" " ReplaceWith="0" All="TRUE" IgnoreCase="FALSE" NoEmbeddedVars="FALSE" _BACK="00C0C0C0"/>
<COMMENT _BACK="00C0C0C0"/>
<IF VARIABLE Variable="%T[1]%" Condition="\x07" Value="%T[2]%" IgnoreCase="TRUE" _BACK="00C0C0C0"/>
<VARIABLE MODIFY STRING Option="\x06" Destination="%T[1]%" Value="%T[2]%  " NoEmbeddedVars="FALSE" _FORE="00808080" _BACK="00C0C0C0"/>
<VARIABLE MODIFY INTEGER Option="\x00" Destination="%N[1]%" Value1="%N[1]%" Value2="1" _BACK="00C0C0C0"/>
<COMMENT _BACK="00C0C0C0"/>
<TEXT BOX DISPLAY Title="Debug : macro to run this turn." Content="{\\rtf1\\ansi\\ansicpg1252\\deff0{\\fonttbl{\\f0\\fnil Tahoma;}{\\f1\\fnil\\fcharset0 Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\lang1036\\f0\\fs16 %T[\\f1 2\\f0 ]%\r\n\\par }\r\n" Left="Center" Top="Center" Width="739" Height="365" Monitor="0" OnTop="FALSE" Keep_Focus="TRUE" Mode="\x00" Delay="0" _ENABLED="FALSE" _FORE="0000FFFF" _BACK="00004080"/>
<COMMENT _BACK="00C0C0C0"/>
<COMMENT Value="Run your macro." _FORE="0040FF00" _BACK="00808080"/>
<MACRO RUN Use_ID="FALSE" Name="%T[2]%" ID="-1" Wait="TRUE" _ENABLED="FALSE" _FORE="0040FF00" _BACK="00808080"/>
<COMMENT _BACK="00C0C0C0"/>
<END IF _BACK="00C0C0C0"/>
<END REPEAT _BACK="00C0C0C0"/>
<COMMENT _BACK="00C0C0C0"/>
<TEXT BOX DISPLAY Title="Debug : verify there is no double." Content="{\\rtf1\\ansi\\ansicpg1252\\deff0{\\fonttbl{\\f0\\fnil Tahoma;}{\\f1\\fnil\\fcharset0 Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\lang1036\\f0\\fs16 %T[\\f1 1\\f0 ]%\r\n\\par }\r\n" Left="Center" Top="Center" Width="739" Height="365" Monitor="0" OnTop="FALSE" Keep_Focus="TRUE" Mode="\x00" Delay="0" _FORE="0000FFFF" _BACK="00004080"/>

 

89997220161026182309.jpg

 

39,37,01,04,33,32,25,14,19,07,08,06,15,13,17,22,03,10,40,12,28,36,38,26,34,00,29,24,21,05,30,20,31,02,11,18,09,16,27,23

 

Important : you must rename your macros, from "1,2,3" to "01,02,03", and "00" is used as name too (you can change this here : Variable Set Integer %N[2]% to a random value between 0 and %N[3]%).

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.

Guest
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.

Loading...
×
×
  • Create New...