Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Roll20 Audio Master - Make sound effects play rapidly

1631041141

Edited 1631042496
Hello, I'm just getting into using scripts and I'm trying to figure out if it's possible to use the same sound effect in rapid succession using a macro. I am using TokenMod, Delay and Roll20AM. I'm running a space rpg with arcade-style spaceship combat and most of the spaceships have macro'd attacks and special abilities. I want my ships to be able to make attacks and jump in and out of hyperspace rapidly without having to wait for the current sound effect to stop playing, so I can create a sense of dread when the players hear a bunch of unexpected new ships warping in, or make them feel badass when they hear the sound of a powerful attack hitting repeatedly etc. Here is my current jumping in macro. Feel free to let me know if I'm doing anything the hard way. I'm pretty new to this stuff. Ships start on the GM layer when coming out of hyperspace. The delay is timed to more or less match up with my uploaded sound effect. !roll20AM --audio,stop,nomenu | HyperJumpIn !roll20AM --audio,play,nomenu,mode:single | HyperJumpIn &{template:desc} {{desc= **@{selected|npc_name}** Emerges from Hyperspace!}}  !token-mod --ids @{selected|token_id} --set tint_color|rgb(256,0,0) layer|objects --move 5.75g /fx nova-blood @{selected|token_id} !delay 1 --!token-mod --ids @{selected|token_id}  --set tint_color|transparent This macro works, but only if I wait for "HyperJumpIn" to finish playing. I want it to play the sound *every* time a ship jumps in, and have them jump in as fast as I can select each one and click the macro button. I do *not* want them to jump in simultaneously and just play the sound once. They should show up one at a time, but rapidly (like the Rebel Fleet showing up to attack the second death star) I thought of trying to upload multiple versions of the sound, but I have no idea how to make the macro pick one that isn't playing and only play that one. I don't want to just spam all the versions at once because then it won't have any freed up to play. Am I chasing an impossible dream here? Can this be accomplished?
1631167046
Victor B.
Pro
Sheet Author
API Scripter
You need to stop hyperjump.  you can issue the stop command or fade out quickly.  Can't control the launch of it.  There's no logic to stop the same track from being launched twice.  Sorry.  You need to launch once when something jumps in.  No way to automate that.  
1631202744
timmaugh
Pro
API Scripter
If you want/need the audio file to continue playing until it finishes, even if another ship should appear, you could probably get something working with a metascript or two. I'll build this for a set of 3 audio files you would upload. They would be the same file, but be named with a suffix of 0, 1, and 2. HyperJumpIn0 HyperJumpIn1 HyperJumpIn2 If you think you might be quicker, or if these files are longer than a second or 2, you might need to have more versions of the same file... but I think 3 would probably cover your needs since you say the 1 second delay coincides with the end of your audio. Next, you need to know, on the fly, which file you should play. We'll track that in a Mule. To do that, create an ability on a mule character (a character not associated with a given character or ship, but which exists just as a launching pad for abilities or to track information). Call the ability "AudioTrack" and structure it like this: HyperJumpIn=0 That's just creating a variable called "HyperJumpIn" that we'll use to store which track we should play. If you wanted to create another variable (say, for jumping into hyperspace, or for ship explosions) you could create it on a new line. Next, you need to play the current track while simultaneously incrementing that variable to be the next, curbing your increments to your upper limit (in this case 2, the last suffix of your files). To accomplish that, we'll use a Muler construct to get & set the variable, and a MathOps construct to control the incrementing. Your Roll20AM command line would now look like: !roll20AM --audio,play,nomenu,mode:single | HyperJumpInget.HyperJumpIn/get set.HyperJumpIn={&math (HyperJumpIn + 1)%3}/set {&mule AudioTrack} That will retrieve the current value of the variable and attach it to the track name to play, then it will increment it by 1 and assign the modulus of that new number and 3... in other words, a 0, 1, or 2. Now your variable is set up to play the next track in sequence, looping from 2 back to 0 when it gets that far. REQUIRED SCRIPTS: Muler, MathOps, and probably ZeroFrame (to keep the others playing nicely)
timmaugh said: If you want/need the audio file to continue playing until it finishes, even if another ship should appear, you could probably get something working with a metascript or two. I'll build this for a set of 3 audio files you would upload. They would be the same file, but be named with a suffix of 0, 1, and 2. HyperJumpIn0 HyperJumpIn1 HyperJumpIn2 If you think you might be quicker, or if these files are longer than a second or 2, you might need to have more versions of the same file... but I think 3 would probably cover your needs since you say the 1 second delay coincides with the end of your audio. Next, you need to know, on the fly, which file you should play. We'll track that in a Mule. To do that, create an ability on a mule character (a character not associated with a given character or ship, but which exists just as a launching pad for abilities or to track information). Call the ability "AudioTrack" and structure it like this: HyperJumpIn=0 That's just creating a variable called "HyperJumpIn" that we'll use to store which track we should play. If you wanted to create another variable (say, for jumping into hyperspace, or for ship explosions) you could create it on a new line. Next, you need to play the current track while simultaneously incrementing that variable to be the next, curbing your increments to your upper limit (in this case 2, the last suffix of your files). To accomplish that, we'll use a Muler construct to get & set the variable, and a MathOps construct to control the incrementing. Your Roll20AM command line would now look like: !roll20AM --audio,play,nomenu,mode:single | HyperJumpInget.HyperJumpIn/get set.HyperJumpIn={&math (HyperJumpIn + 1)%3}/set {&mule AudioTrack} That will retrieve the current value of the variable and attach it to the track name to play, then it will increment it by 1 and assign the modulus of that new number and 3... in other words, a 0, 1, or 2. Now your variable is set up to play the next track in sequence, looping from 2 back to 0 when it gets that far. REQUIRED SCRIPTS: Muler, MathOps, and probably ZeroFrame (to keep the others playing nicely) Wow, thanks for the thorough response! I'll get ahold of those scripts and give this a try, then reply here to let you know how it goes. You have my sincere gratitude, sir or madam!
Okay, here's my macro to make a ship jump into hyperspace !roll20AM --audio,play,nomenu,mode:single | HyperJumpget.HyperJump/get set.HyperJump={&math (HyperJump + 1)%3}/set {&mule AudioTrack} &{template:desc} {{desc= **@{selected|npc_name}** jumps into Hyperspace!}} !token-mod --ids @{selected|token_id} --set tint_color|rgb(256,0,0) !delayt 1 --!token-mod --ids @{selected|token_id} --move 5.75g !delay 1.5 --!token-mod --ids @{selected|token_id} --set layer|gmlayer !delay 1.55 --!token-mod --ids @{selected|token_id} --set tint_color|transparent !delay 1.5 --!cfx nova-blood @{selected|token_id} @{selected|token_id} When I click it, it prints "(Ship Name) jumps into hyperspace!" in the chat, but none of the other parts of the macro happen, and it crashes the API with this message: URIError: URI malformed URIError: URI malformed at decodeURIComponent (<anonymous>) at cmdExtract (apiscript.js:620:18) at apiscript.js:506:34 at Function.each (/home/node/d20-api-server/node_modules/underscore/underscore-node-f.cjs:1323:7) at inputHandler (apiscript.js:503:19) at eval (eval at <anonymous> (/home/node/d20-api-server/api.js:168:1), <anonymous>:65:16) at Object.publish (eval at <anonymous> (/home/node/d20-api-server/api.js:168:1), <anonymous>:70:8) at /home/node/d20-api-server/api.js:1732:12 at /home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:560 at hc (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:39:147) What did I mess up here?
Victor B. said: You need to stop hyperjump.  you can issue the stop command or fade out quickly.  Can't control the launch of it.  There's no logic to stop the same track from being launched twice.  Sorry.  You need to launch once when something jumps in.  No way to automate that.   I did try this approach, but the stop command didn't seem to stop the sound. Did I format that incorrectly?
1631210223
timmaugh
Pro
API Scripter
Hmm... Did you import the new tracks to Roll20AM?
That did give me an error at first, but I re-imported all my tracks and tried again and it still crashed.
1631217415
timmaugh
Pro
API Scripter
One other piece of potential low hanging fruit... you apparently changed your audio track name as well as the variable name. Where I had HyperJumpIn you have HyperJump. That's fine, just make sure that your variable is also correctly named. So if you're looking for a variable named HyperJump in the AudioTrack Mule: get.HyperJump/get {& mule AudioTrack} ...that mule should look like: HyperJump=0 Then, based on the way you have the macro written, the command line will deliver audio track names of: HyperJump0 HyperJump1 HyperJump2 ...so make sure those match what you've uploaded/imported. I'm having trouble getting R20AM to run in my test game, so if there's still a problem there's one other thing you can try while I try to get things sorted over here. I think it is R20AM that is breaking, because nothing I gave you should have triggered a URI decoding. But what that means is that we're not delivering the name of the audio track properly to the command line as R20AM receives it. Provided you have ZeroFrame installed, add {& simple} to your roll20AM command line: !roll20AM......... {&simple} That will turn the finalized command line (after all Roll20 and metascript work is done) into a simple chat output instead of an api call. You can then check the result of all of our work, and confirm whether the audio track name is being delivered correctly. (IOW, it won't actually hit Roll20AM -- it will be diverted before that point -- allowing you to see the command line that *would have* reached Roll20AM. If it gets that far and your API does NOT break, then the problem is occurring within R20AM based on the command line we are feeding it.)
Hey, I really appreciate your help with this! I'll give that a try as soon as I get back to my computer and let you know what happens. I did remember to change the name to HyperJump everywhere, so that's not it (that was my first thought too). 
Okay, here's what I got back in the chat log: audio,play,nomenu,mode:single | HyperJump{&math (HyperJump + 1)%3}
Is &mule a stand-in for a character's name? cause I used that verbatim and named the character with the AudioTrack ability "mule"
Not sure if this is helpful, but when I open the AudioTrack ability, it doesn't have actual numbers assigned to the variables. It assigned a section of code from the macro: HyperJumpIn={&math (HyperJumpIn + 1)%3} HyperJump={&math (HyperJump + 1)%3} I don't know if that's helpful in diagnosing it. The Jump In/Out macros will work once, then crash the API once the AudioTrack Ability looks as it does above.
1631241918
timmaugh
Pro
API Scripter
Ah... It looks like you don't have the MathOps script installed/enabled... otherwise that little construct would parse out of the line: {&math (HyperJump + 1)%3} That would become either 0, 1, or 2. Also, "mule" is in some contexts a general term for the kind of character storing launchable ability command lines or attribute information. Sometimes you will hear people talk about a "macro mule" as a way to get abilities from game to game without losing them. In other contexts (like the Muler script), a "mule" can refer specifically to the ability that stores a table of information. Your "AudioTrack" ability is a mule. When you see this construct: {& mule ...} That is a little syntax token that tells the Muler script, "Go out and get these mule abilities, and make the variables available to all of my get & set statements." In your case, you tell it to go out and get the AudioTrack mule ability. The name of the character can be anything and isn't related to "mule" at all. The only time the name comes into play with the Muler syntax is if you want to differentiate between the AudioTrack mule ability on Bob versus the AudioTrack on Volcano Man. In that case, you could load Bob's mule ability specifically using: {&mule Bob.AudioTrack} Similarly, if you needed to get/set a variable that might exist on 2 mules loaded into the same message, and you want the specific value from one, you can differentiate using the character there, too: get.Bob.HyperJump/get
Wow, I thought I had installed MathOps. I definitely opened it in the one-click API script thing, but I guess I did a sausage-fingered slide-click when I clicked 'add script'. It's working now! Thanks for your help! This is really gonna up my game.
I actually looked this up and it turns out you can adjust how many pixels you have to move the mouse before windows considers it "dragging" so hopefully that won't happen again, and maybe someone will see this someday and find my mistakes useful. I think using a tablet with a hi-res but small sized screen with weird zooming applied didn't help. I actually had the same slide-click problem when I went to hit "Submit Post" on the last reply XD
1631244666
timmaugh
Pro
API Scripter
Excellent! Glad to help!
I'm tacking this on the end here because it's related. I currently have a map that is serving as a view screen for the players to talk to aliens Star Trek style. When I load up the alien's image using token mod, I want to also play their theme song in the jukebox. I have roll20AM doing this, and it works, but it plays the track from where it last left off instead of restarting it. Is there any way to make it always start playing at 00:00, but still loop if the players keep talking to that alien for a while? I'm using the name of each alien's image token to store the name of their theme track. I'm also using Fetch here, to avoid problems with parsing the enormous query to pick the alien. Here's my macro, for reference. !roll20AM --audio,play,loop,nomenu | @(?{Alien|Androsynth,-Mk9JpyOk1Uq0k86ymqb|...a bunch of alien names|token id's...}.token_name)