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

Rolling dice and using the result (in API)

1429393269
Kryx
Pro
Sheet Author
API Scripter
Hi, I'm trying to roll the dice on roll20 and use the result, but I keep getting: undefined:1 $[[1]] ^ SyntaxError: Unexpected token $ at Object.parse (native) at evalmachine.<anonymous>:176:26 at checkFinishedOps ( I'm using this javascript: sendChat('', '[[' + '26d6' + ']]', function(ops) { log('test'); var rollResult = JSON.parse(ops[0].content); log('rollResult: ' + rollResult); }); If I instead send sendChat('', '26d6', function(ops) { log('test'); var rollResult = JSON.parse(ops[0].content); log('rollResult: ' + rollResult); }); I get undefined:1 26d6 ^ SyntaxError: Unexpected token d at Object.parse (native) at evalmachine.<anonymous>:171:26 at checkFinishedOps ( It never gets to 'test'. What am I doing wrong?
1429395847
Kryx
Pro
Sheet Author
API Scripter
It has to be '/roll 26d6'. That's what was wrong.
1429408242

Edited 1429408267
Lithl
Pro
Sheet Author
API Scripter
Yes. if type == 'rollresult' (you use the /roll command), content is a JSON string. If you're not using /roll, type will be something else, content will not be a legal JSON string, and trying to parse it as such will most likely fail. If you use inline rolls, the inlinerolls property will be a JSON string you can parse.
1429419927
The Aaron
Pro
API Scripter
If you use inline rolls, the inlinerolls property will be a JSON string you can parse. .. an array of objects representing the rolls. See: <a href="https://wiki.roll20.net/API:Chat" rel="nofollow">https://wiki.roll20.net/API:Chat</a>
1429474977
Lithl
Pro
Sheet Author
API Scripter
The Aaron said: If you use inline rolls, the inlinerolls property will be a JSON string you can parse. .. an array of objects representing the rolls. See: <a href="https://wiki.roll20.net/API:Chat" rel="nofollow">https://wiki.roll20.net/API:Chat</a> I blame the middle of the night. =P
1429495170
The Aaron
Pro
API Scripter
I knew what you meant. :)