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)

April 18 (10 years ago)
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?
April 18 (10 years ago)
Kryx
Pro
Sheet Author
API Scripter
It has to be '/roll 26d6'. That's what was wrong.
April 19 (10 years ago)

Edited April 19 (10 years ago)
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.
April 19 (10 years ago)
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: https://wiki.roll20.net/API:Chat
April 19 (10 years ago)
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: https://wiki.roll20.net/API:Chat

I blame the middle of the night. =P

April 20 (10 years ago)
The Aaron
Pro
API Scripter
I knew what you meant. :)