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

[Help] error on trying to send text to chat

1383287211

Edited 1383290253
I made a script to show the degrees of success or fail for the 40k skill tests. The script calculates the correct values, but I get the following error when I try to send it to chat. For reference, the error message generated was: SyntaxError: Unexpected token y at Object.parse (native) at evalmachine.&lt;anonymous&gt;:5:24 at eval ( It runs once correctly then I get the above error message in the log and it wont run again. I cant for the life of me figure out what is going wrong with the code, it works 1005 fine until I put in the two sendChat methods. <a href="https://gist.github.com/lostaris/3321fa360065358c4fa7" rel="nofollow">https://gist.github.com/lostaris/3321fa360065358c4fa7</a>
1383372301

Edited 1383372454
Lithl
Pro
Sheet Author
API Scripter
var message = JSON.parse(msg.content); Your script is calling sendChat , which then triggers the "chat:message" event again. msg.content is only a JSON string if msg.type is "rollresult". Any other message type will (most likely) not have a correctly-formatted JSON string stored in msg.content, so JSON.parse will throw an error. ("Unexpected token y" is referring to the fact that the first character of message.content is "y" -- the content of your message, you rolled test Degrees of success/fail .) Check msg.type to see whether it's actually a rollresult message first.
Yeah I completely forgot to check for the roll type -_- if (msg.type == 'rollresult') { at the top fixed it