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

outputmessage

I am trying to send to chat results of Melf's Acid Arrow.   var outputMessage = `&{template:default} {{name=Melf's Acid Arrow}} On hit ${DmgOutput} with next turn damage for ${DmgOutputturn}`; sendChat("API",outputMessage); This is not working.  Also how would I w to GM here? Thanks,
1597701623
GiGs
Pro
Sheet Author
API Scripter
when you its not working, what exactly is happening? Also the last part of your message is not included in {{ }} braclets so will be ignored, and not be printed to chat. You can add /w GM to the very start of the string, like sendChat("API",'`/w GM ' + outputMessage); or var outputMessage = `/w GM &{template:default} {{name=Melf's Acid Arrow}} On hit ${DmgOutput} with next turn damage for ${DmgOutputturn}`;
If i just use  var outputMessage = `&{template:default} {{name=Melf's Acid Arrow}} ${DmgOutput} `; sendChat("API",outputMessage); it outputs into chat the results of $DmgOutput in the template with the name Melf's etc.  When I use the first code I posted it sends the same information for  ${DmgOutput} Here is the entire function: function MelfAcidArrow(spellLevel, tokenName){ var DmgOutput = ""; var DmgOutputturn = ""; var DmgOutputmiss=""; DmgOutputmiss+=`${DmgOutput}/2`; DmgOutputturn += `{{[[(2+(${spellLevel}-2))d4]] Acid Damage}}`; DmgOutput+=`{{Attack [[1d20+@{${tokenName}|spell_attack_bonus} ]] for [[(4+(${spellLevel}-2))d4]] Acid Damage}}`; var outputMessage = `&{template:default} {{name=Melf's Acid Arrow}} On hit ${DmgOutput} with next turn damage for ${DmgOutputturn}`; sendChat("API",outputMessage); var outputMessage = `&{template:default} {{name=Melf's Acid Arrow}} On Miss ${DmgOutputmiss} with no damage next turn`; sendChat("API",outputMessage); } I would like to /w Gm (which it now does cause i saw your advice) and would like to see it with the a full description for Melf's damage.  so something like: message one would be: Attacks for <attack roll result> on hit xd4 Acid damage with xd4 damage next turn Message two would be On miss xd4 damage with zero damage next turn. I know I am becoming a pain thanks,
1597722898

Edited 1597722986
GiGs
Pro
Sheet Author
API Scripter
Don't worry about being a pain. Learning this stuff is painful! We have all been there, and are here to help. Your function has a few problems. you have dmgoutputmiss being set as dmgoutput/2 but before dmgoutput is defined, and then dmgoutput is a string, so dmgoutput/2 doesnt work. Both of those will likely cause your script to crash.  I would combine the sendChats and build it more like this: function MelfAcidArrow(spellLevel, tokenName){     var start = `&{template:default} {{name=Melf's Acid Arrow}}`;     var attack = `{{Attack=[[1d20+@{${tokenName}|spell_attack_bonus} ]]}}`;     var hit = `{{Hit=[[(4+(${spellLevel}-2)/2)d4]] Acid Damage}}`;     var miss = `{{Miss=[[(4+(${spellLevel}-2)/4)d4]] Acid Damage}}`;     var nextturn = `{{Next Turn=[[(4+(${spellLevel}-2)/2)d4]] Acid Damage (if Hit)}}`;          var outputMessage = `/w GM ${start} ${attack} ${hit} ${miss} ${nextturn}`;     sendChat("API",outputMessage); } I had to guess at the damage because I think there's an error in your code. Yours says  [[(2+(${spellLevel}-2))d4]] But that looks like two many brackets, making me think there should be a divisor in there, probably 2.
I will try this later.  I was thinking of doing something like this, but thought I was on the right track for building a string with variables inserted. so you can't do something like: "There are " & variable & " stars in a blue field, with " & Variable2 & " white strips, and " & variable3 & " red strips on the US flag." That would work in VBA (my wheelhouse). Thanks,
1597756419

Edited 1597756445
timmaugh
Pro
API Scripter
The concatenation operator in javascript is + (though you have to be careful about your types, because that is also the addition operator)... but you can drop into code if you operate in template literals, instead. To use a template literal, enclose the string in tick marks (`) instead of single- or double-quotes. Then in the middle you can basically drop into js statements using the ${} formation... let schmackah = 'Bing bong'; let outputString = `Let's drop that variable right here: ${schmackah}`; That's a simple version. You can also do things like ternary comparison: let schmackah = 'Bing bong'; let outputString = `It is time to bing the bongs. ${schmackah === 'Bing Bong' ? schamackah : 'I have no bongs to bing.'}`;
1597770135

Edited 1597770173
GiGs
Pro
Sheet Author
API Scripter
In addition to Tim's amusing examples, I could have done this: var outputMessage = '/w GM ' + start + attack + hit + miss + nextturn; So yes, you can concatenate just like in VBA (which was my first programming language too!). I did it with the template literal syntax because you used that in your code, and I tried to make that function using the same structures you used so it would be more familiar with it.