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

[Help] Why does this code not work?

January 05 (10 years ago)

Edited January 05 (10 years ago)
sendChat("DM", "/roll 1d100", function(ops){
sendChat("DM", ops[0]);
});

On Dev server, return error: undefined:322 op.content = op.content.replace(abilreg, function(match) { ^ TypeError: Object has no method 'replace' at Object.d20.textchat.doChatInput (
January 05 (10 years ago)

Edited January 05 (10 years ago)
Lithl
Pro
Sheet Author
API Scripter

ops[0] is the same kind of object as msg in on('chat:message', function(msg) {...});. sendChat expects a string. In your example, ops[0].type would be 'rollresult', meaning ops[0].content is json roll data. So, if you want to for example send the final result to the chat, you could use JSON.parse(ops[0].content).total.

January 05 (10 years ago)
So much yet to learn. Thanks for the direction.
January 06 (10 years ago)

Edited January 06 (10 years ago)
With much help and a lot of thinking, this is what I've come up with to handle this small piece of a much larger pie. It is working great. Thanks.

I should add, the process inline rolls function is straight off the wiki: https://wiki.roll20.net/API:Cookbook#processInline...
To whomever wrote that,cheers!

https://gist.github.com/limpinjezus/5eb527f261bb2d03c11a
January 06 (10 years ago)
Lithl
Pro
Sheet Author
API Scripter

Michael said:

I should add, the process inline rolls function is straight off the wiki: https://wiki.roll20.net/API:Cookbook#processInline...
To whomever wrote that,cheers!

That would be Aaron who wrote the snippet. =)

January 07 (10 years ago)
The Aaron
Pro
API Scripter
Awesome! Glad you found it useful! =D