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

[Help] Question about utilizing API with Jukebox

Hey guys, apologies in advance if this has been asked before, but... I've been a Pro subscriber for a little while now, but never really messed around with the API editor outside of copy/pasting pre-made scripts (a common use of the API function, I understand) and altering a line or two here and there within the script, but I've never delved too far into the "language" of scripting, as it were.  Anyway, with the recent Jukebox/API integration update, I'm suddenly verrrrry interested in finding out how to call sound effects from my Jukebox, but I am unfortunately very API illiterate. I've scouted out several API tutorials around the web, but I'm afraid I'm just not that technically minded and I find myself often left even more baffled after reading them.  What I wanted to know was if there was a way to set up a script to play certain Jukebox tracks by way of an API chat command (i.e. !battlecry) and if so, would one of you API wizards be willing to share the information with a humble API peasant such as myself? I'd greatly appreciate any information that could help enhance the games I'm running for my players. Thanks in advance. Also, this is my first post, so if I've posted in the wrong forum, I sincerely apologize. 
1443700902
The Aaron
Pro
API Scripter
This is the right forum and welcome to it! =D Brian has a script he's working on for this: &nbsp; <a href="https://app.roll20.net/forum/post/2459136/script-t" rel="nofollow">https://app.roll20.net/forum/post/2459136/script-t</a>... I have plans for one as well, but less time to devote to it.&nbsp;
Cool! The script looks pretty much like what I was looking for, and I'm excited to check it out.&nbsp; Thanks for the quick reply, too! &nbsp;
Okay, I've played around with the script and managed to link a track to an alias. However, I am having trouble linking the alias to a trigger event.&nbsp; I'd like to link to a chat:message event, but as I said before, I'm unsure how API syntax is organized (I am further confused by the mention of lambda expressions being necessary).&nbsp; Is there any way to provide me a small example of how to properly write the code to bind an alias to a chat:message event?&nbsp; I understand you're all busy, and I appreciate the hard work that goes into maintain and enhancing this awesome system, but any help or advice would be welcomed and revered.&nbsp; (I'll post this in Brian's post as well, so feel free to delete this message if you deem necessary)
1443718185
The Aaron
Pro
API Scripter
No problem. &nbsp;I'll let Brian answer you on the other thread, I've not played with it yet. Basically, you have to write javascript as an argument to the command to setup the event trigger, something like: !triggersfx chat:message (msg.content.match(/fireball/i) ) ? play('boom') : 0 This would examine each chat message for the string "fireball" (case-insensitive) and if it found it, would play the aliased sound 'boom'.
1443728776

Edited 1443730560
Alright, I'm starting to understand it now. Just to clarify, though, the example you gave me -&nbsp; !triggersfx chat:message (msg.content.match(/fireball/i) ) ? play('boom') : 0 - should be typed into the chat message window just like any other "!" API command function, right?&nbsp; This should be the last question I have regarding this API/Jukebox relationship. I am indebted to you for your patience and help.&nbsp; Thanks! Update:&nbsp; I tried inputting the command into the chat window to set up the chat message trigger event and the API came back with the following error:&nbsp; /home/symbly/www/d20-api-server/node_modules/firebase/lib/firebase-node.js:1 orts, require, module, __filename, __dirname) { function g(a){throw a;}var j=v ^ SyntaxError: Unexpected token ) at Object.Function () at String.lambda (evalmachine.:459:12) at Object.bshields.sfx.commands.triggersfx (evalmachine.:133:121) at handleInput (evalmachine.:360:38) at eval ( Update 2:&nbsp; (From System): An error occurred! A triggered event failed. Error message: TypeError: Cannot call method 'play' of undefined Event: function anonymous(msg) { return ((msg.content.match(/moan/i) ) ? this.this.play('groan') : 0) } So, when attempting to run the trigger event in the chat window, it returned this message. ('moan' is the chat trigger I wish to use and 'groan' is the alias I assigned my chosen track) Confusion abounds! Yay! :D&nbsp;
1443748639
Lithl
Pro
Sheet Author
API Scripter
Joshua R. said: Update 2:&nbsp; (From System): An error occurred! A triggered event failed. Error message: TypeError: Cannot call method 'play' of undefined Event: function anonymous(msg) { return ((msg.content.match(/moan/i) ) ? this.this.play('groan') : 0) } So, when attempting to run the trigger event in the chat window, it returned this message. ('moan' is the chat trigger I wish to use and 'groan' is the alias I assigned my chosen track) Confusion abounds! Yay! :D&nbsp; When you created the trigger, did you write "this.play('groan')" or "play('groan')"? The script automatically prepends "this." to play calls, so if you created your trigger with "this.play" it'll get translated to "this.this.play", which is an error.
1443819485
Scaby79
Sheet Author
API Scripter
The Aaron said: No problem. &nbsp;I'll let Brian answer you on the other thread, I've not played with it yet. Basically, you have to write javascript as an argument to the command to setup the event trigger, something like: !triggersfx chat:message (msg.content.match(/fireball/i) ) ? play('boom') : 0 This would examine each chat message for the string "fireball" (case-insensitive) and if it found it, would play the aliased sound 'boom'. *lol I tried that! 😉 Unfortunately the script gave out an error message IN THE CHAT with the word "fireball" in it, but that again tried to trigger the sound, which resulted again in another error message with the word "fireball" in it... You can see, where this is going? I could stop the fun with !deletetriggersfx chat-message