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

[Bug]/w GM using sendChat from player doesnt show text sent to player

1391072364

Edited 1391073932
DXWarlock
Sheet Author
API Scripter
I'm assuming this is a bug, as sending a /w as a player using API should/would show the player the message sent? if I do a sendChat(msg.who, '/w GM test'); The player/character of msg.who does not see the text the same as if they did a /w gm. This causes a problem if you're doing any API scripts that automate the player sending a private roll to GM or rolling on a rollable table, as they dont see the result. I COULD send it to both GM and player as two sendChats. the issue arises that when doing that, and the rollable table has '[[1d8]] Torches' for example, the player and GM get different results as its rolled for each sendChat Then again I could parse the text returned, look for anything like a inline roll, take it out and parse out the dice, do a roll in the API of that amount to make a variable, then rebuild the result with that number to send to both player and GM. But seems silly to go thru all that, when doing /w GM as a player, it makes sense the player should get the '(To GM): test' on their end if its sent as them.
1391075037
Alex L.
Pro
Sheet Author
Chat messages coming from sendChat never registers as coming from who you specify, it merely puts the sting you enter in the chat log. A way to get round the problem would be to read the roll then output the result to both people.
1391075336

Edited 1391075629
DXWarlock
Sheet Author
API Scripter
Well crap..lol How would I go about that, its what I'm trying to do now. The problem is finding the inline rolls in the results and getting it to generate a number to save and rebuild the result to send. Like it can pull "[[1d8]]Glow Sticks" or "E-Clip [[1d12]] shots left" from the rollable table. The API sees it as a roll and generates a number automatically in the results sent, which was really nice as just rolling the table directly didn't do that. I've been fighting with it an hour trying to reliably pull out the [[whatever]] out of the result, roll it, save it as a variable, and replace it in the loot variable to send to both people. Like this is what im doing now sendChat('', "/roll 1t[RandomWA]", function (ops) { var loot = JSON.parse(ops[0].content).rolls[0].results[0].tableItem.name; sendChat(msgWho, '/w gm WEAPON: ' + loot); sendChat(msgWho, "/w " + msgWho + ' WEAPON:' + loot); }); But been hacking away at it to get 'loot' find the inline roll, and make a 'count' variable to stick back into loot. But its beyond what I can figure out.
1391076330
Alex L.
Pro
Sheet Author
inline rolls are in msg.inlinerolls its an array and the number you get back in the message ie "$[[0]]" is the index in the array in this case 0.
1391076574

Edited 1391077264
DXWarlock
Sheet Author
API Scripter
The problem with that is the inline roll isn't calculated until the message is sent, when it returns the table result its this if I do a log(loot); "Stainless steel chain, [[2d6]] feet is usable" "[[2d20]] Feet of Rope" I need to catch the results, figure out what is a roll, and roll it, so its sent to both people the same. if I used msg.inlinerolls it means its already sent to both people as different rolls to chat :\ See what I mean? I even tried catching whispers, sending loot results only to the player and just relaying whispers to the GM, using on('chat:message', function(whisper) { but runs into that $[[1]](rolling 0d0=0) bug/result when trying to /w gm whisper.content. :(
You need to use msg.inlinerolls[#].results.total to get the value of $[[1]] and then use str.replace("$[["+ rollnumber + "]](rolling 0d0=0)", msg.inlinerolls[#].results.total) somehow.
1391088077

Edited 1391088206
DXWarlock
Sheet Author
API Scripter
Oh that might be a lot easier than what Im doing.. I ended up making a function like this: function myrolls(loota) { for(var i = 0; i < loota.length; i++) { var ii = (loota[i].indexOf("[[") != -1); if(ii == true) { var num = loota[i].replace(/[^0-9]/g, ''); var res1 = num.substr(0, 1); var res2 = num.substr(1, 4); var i = 1; var tot = 0; log('------------'); log(res1 + 'd' + res2) while(i <= res1) { var tot = tot + randomInteger(res2); i++ } return tot; } } } I make the entire return text an arraylist and send it to this, Then look at each part, if it starts with [[, the remove the [[ and ]], get the first number, then the 3rd up to 4 digits, then do a while to roll the 3rd a number of times equal to the first number first and total it..then return it..it works ok...just overly complicated..lol Now just trying to workout how to replace [[somedice]] in a var using var.replace and regex..getting it to take a '[' as the character to look for starting a word, and replace the whole word with with the returned value is being fussy. I thought var lootE = loot.replace(/\b[[\[]]*/g, tot); would do it, but its not. 2 hours to make the script, 6+ hours trying to replace a single part with a total..lol
I just use str.indexOf to find things.
1391089886

Edited 1391089970
DXWarlock
Sheet Author
API Scripter
I got it! var lootE = loot.replace(/\[.*?\]\]/g, a); all that to send the same roll to 2 people :P
You could have done the same with a while loop using the length of the msg.inlinerolls array as the counter.
1391090909

Edited 1391091264
DXWarlock
Sheet Author
API Scripter
But it still wouldn't solve the problem of having to send it to me and the player so we both see it, and getting 2 different results to parse. Unless I send it only to him, and did the catch whispers, and, make another huge parser just to send me the message using that. Unless Im missing what your meaning from being burned out staring at this one all night :P Next time i need to parse the $[[0]] I will remember it, so thanks for pointing it out. I've had to work around it before on my crit hit script, might go back and work it out in that one.
1391092359
Alex L.
Pro
Sheet Author
William R. said: But it still wouldn't solve the problem of having to send it to me and the player so we both see it, and getting 2 different results to parse. Unless I send it only to him, and did the catch whispers, and, make another huge parser just to send me the message using that. Unless Im missing what your meaning from being burned out staring at this one all night :P Next time i need to parse the $[[0]] I will remember it, so thanks for pointing it out. I've had to work around it before on my crit hit script, might go back and work it out in that one. you could have the inline roll in the original command.
1391092746

Edited 1391093077
DXWarlock
Sheet Author
API Scripter
its pulling it from a rollable table, it doesn't see it as inline until its send to chat, it literally comes back as plain text as: "Stainless steel chain, [[2d6]] feet is usable" its not an inline roll until I send it to someone from the API as a sendChat