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

Can a script return a value to a macro?

1388003733
Sam
Sheet Author
Is it possible to for a script to return a value to a macro or character ability? I want to write a truncate script that handles either negative or positive numbers since using just floor or ceiling is insufficient if you are expecting values with either negative or positive signs. If the value is positive and you use ceiling or if the number is negative and you use the floor then the number 1 too high. I want to be able to write a !trunc script that would have a simple logic test to check the sign of the number and then call the appropriate truncation function.
1388023174

Edited 1388023196
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
yes.. this is just something pretty much random code I plucked from one of my scripts setting an attribuite to "-" findObjs({ _type: "attribute", name: "CodeA3", _characterid: GM_Chronosid})[0].set({current: "-"});
1388029406

Edited 1388029424
Sam
Sheet Author
That's setting the value of a known attribute. It's not a the same as returning a value which is then usable by the calling macro. What would happen if I wrote a script called !trunc that did <a href="https://gist.github.com/jarquafelmu/8129508" rel="nofollow">https://gist.github.com/jarquafelmu/8129508</a> And then called it by saying [[(!trunc 10/3) + 5]]
Nope, that does not work.
1388055797
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
!trunc (10/3) + 5 You could do that...... no reason you can't do that. But its not going to process a API command as an inline result.
1388081636
Sam
Sheet Author
How do you write a result back to the chatbox? or the macro do you do document.write(value)?
1388084211
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
You can do all the work in the API. Rather then writing a macro that rolls dice and grabs stuff from attributes etc.... just do it all in the API. There is nothing a macro can do that an API script cannot do... plus the API lets you do anything you want with JavaScript to process the results before send them to chat.
1388084392
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
And you could.... take a macro "!roll 1d20 + @{selected|bar1}".... ...do something in API with Bar1 and send to the chat "/roll 1d20 + @{selected|bar1}"
1388130668
Sam
Sheet Author
How would I pull the value of @{selected|bar1} in the API?
1388140146
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
Parse it out... If the selected bar1 value is 9.... the msg.content will be "!roll 1d20 + 9" if(msg.content.indexOf(' ') == -1){ var myMesssage = null; var myCommand = msg.content.substr(1, msg.content.length); }else{ var myCommand = msg.content.substr(1, msg.content.indexOf(' ') - 1); var myMesssage = msg.content.substr(msg.content.indexOf(' ') + 1); }; if(myMesssage !== null){ try{ var parts = myMesssage.toLowerCase().split(' '); sendChat('', parts[0], function(outs) {}); var diceRoll = parts[0]; }catch(e){ diceRoll = undefined; }; }else{ diceRoll = undefined; }; The above might have a error in it (didn't test it) but it should give you: Message sent, API command, and any valid dice rolls. Since you should know the format of the macro, that should be enough to work it all out. Or use.... " !attack @{selected|character_name}" You should know who sent the API command (msg.who), and you know what they want to do ("attack') and you now know the character_name of who they want to attack.