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

In Search Of: A SIMPLE roll comparison script that works with inline rolls

1410469606
Gen Kitty
Forum Champion
So I found this script: <a href="https://app.roll20.net/forum/post/150221/script-ro" rel="nofollow">https://app.roll20.net/forum/post/150221/script-ro</a>... The problem I have is that it doesn't seem to work with inline rolls. I'm looking for a script that will let me do a macro such as (using the aforementioned script as an example) @{selected|token_name} attempts to Bull Rush @{target|token_name}! Result: [[ /r 1d20+@{HalfLevel}+@{STR} +?{MiscMod?|0} |&gt;| @{target|Fort} ]] And get output such as: Billy attempts to Bull Rush Goblin3! Result: Success Does this currently exist? How hard is this to make? (My brains melt every time I try working with API)
1410496135
The Aaron
Roll20 Production Team
API Scripter
I don't think it exists currently. It is possible to get the results you want, but you'd need to do it a bit differently: you'd want the second line to be an API command and you'd want to pass it a few inline rolls instead of trying to monkey with the inline roll format, then you'd want to do the comparison and write the output from the script.
You could possibly do it via a rollable table.
1410530194

Edited 1410530268
DXWarlock
Sheet Author
API Scripter
What Aaron said would be a lot easier, It wouldn't be a huge script at all. I saw the post yesterday and thought "Ah that shouldnt be hard ill try it" then realized I never did a script with a selected, and a separate clickable target, couldnt figure out how to have the API ask you to 'who' the target it with a @{something}. But then my api/javascript grasp is just enough to get me by on my own scripts :P
1410536460
The Aaron
Roll20 Production Team
API Scripter
That second line would look something like this: !isgreater [[1d20+@{HalfLevel}+@{STR}+?{MiscMod?|0}]] @{target|Fort} Off the cuff, this would do the above: GIST: <a href="https://gist.github.com/shdwjk/a7968b474c7fa56a89f5" rel="nofollow">https://gist.github.com/shdwjk/a7968b474c7fa56a89f5</a>
1410540175
The Aaron
Roll20 Production Team
API Scripter
Incidentally, that will work for any method of specifying the numbers to either argument: !isgreater [[1d20+@{HalfLevel}+@{STR}+?{MiscMod?|0}]] @{target|Fort} !isgreater [[1d20+@{HalfLevel}+@{STR}+?{MiscMod?|0}]] 10 !isgreater [[1d20+@{HalfLevel}+@{STR}+?{MiscMod?|0}]] [[ @{target|Fort} ]] !isgreater ?{Pick a number| 7} @{target|Fort} !isgreater 23 10
1410541663
DXWarlock
Sheet Author
API Scripter
See I only understand 1/2 of that script :) the way you do functions of X = function() confuses me vs function X () the use strict, and the whole var IsGreater = IsGreater || (function() { still confuses me despite reading that other post of yours explaining it like 4 times..ha. Good thing Aaron is around, I was still trying to make a script to do what you wanted, Id have had it done for you by the 1st week of Oct for sure!
1410547289
The Aaron
Roll20 Production Team
API Scripter
=D If I wanted to REALLY confuse you, I'd sprinkle in things like: if( 1..isEven() ) { // something } In Javascript, everything is an object. So: var foo = function() { // something }; Is just creating a function anonymously and assigning it to the variable foo . It's almost the same thing as: function foo () { // something } I do it that way because it keeps that idea that it's just an object forefront in my mind when reading it. Check THIS out: var foo = function bar () { log('bar is a '+(typeof bar)); log('foo is a '+(typeof foo)); }; foo (); // bar is a function // foo is a function var qux = foo ; foo = 10; qux (); // bar is a function // foo is a number You can still give a name to a function (which means it's not anonymous anymore I guess. =D ), and that name is defined inside the function object regardless of what variable is holding it. This is particularly important for recursive functions. This is part of what makes Javascript so dynamic, since everything is an object, anything can be passed around, which is why callbacks work so well. =D Back to that confusing example above, since everything is an object, the number 1 is, and has methods. Since the Javascript engine recognizes numbers a something akin to /\d+.?\d*/, the first . is the radix point (decimal point for decimal numbers!) and the second . is the property accessor for objects. 1..isEven(); // valid (1).isEven(); // also valid var foo = 1; foo.isEven(); // valid and much more likely to be seen. =D Hope that clears it up! =D Cheers!
1410548215
Gen Kitty
Forum Champion
Yay, I appreciate the script. It does exactly what I asked for, and it works inside a macro. You get many cookies and positive karma for this! However, I discovered I missed a design constraint (because I'm an idiot) which probably sinks the whole project: We need to be able to mouseover it and see the roll/math so A) we can see if someone critted and B) I can make sure the math is pulling in all the right numbers. Still, you did exactly what I asked for and I'm sorry I didn't ask for exactly what I wanted. :/
1410552871
The Aaron
Roll20 Production Team
API Scripter
No worries, I wondered about that. There is a way to do that, HB's power cards do exactly such. I'll see about adding that in later today. =D
1410553136
Gen Kitty
Forum Champion
*wistful* I'd love to use HB's power cards. They're *awesome*. But last I checked, they don't handle stuff that handles variable targets well (IE, AoE's that could have one or more targets).
1410555720
Lithl
Pro
Sheet Author
API Scripter
The power card script handles variable number of targets just fine. --attack?{Number of Targets|1}|[[d20+12]] for example
1410556072
Gen Kitty
Forum Champion
When did that change happen? I haven't looked at the card script in something like 4 months because I gave up on it.
1410559940
Lithl
Pro
Sheet Author
API Scripter
Um... I think the syntax for it changed a little at once point, but the power cards script was capable of handling multiple attack rolls on its first full release, back when it was D&D 4e only (instead of the more generalized version it is now). The first screenshot of the feature in-progress was February 6.
1410560789
Gen Kitty
Forum Champion
I will take another look at the script then. I was able to do some very simple powercards as a proof of concept, but getting beyond that failed terribly. (Working with API scripts in general around here make me feel like the veriest of idiots, so I tend to avoid them)
1410575475

Edited 1410575500
The Aaron
Roll20 Production Team
API Scripter
OK. As a shortcut, I made this work with the buildinline() function from HB's Powercards. You'll need to install that for this version to work: // GIST: <a href="https://gist.github.com/shdwjk/" rel="nofollow">https://gist.github.com/shdwjk/</a> var IsGreater = IsGreater || (function() { 'use strict'; var version = 0.2, HandleInput = function(msg) { var args, values={}, inline={}, v1,v2,d1,d2; if (msg.type !== "api") { return; } if(_.has(msg,'inlinerolls')){ _.each(msg.inlinerolls, function(v,k){ values['$[['+k+']]']=v.results.total || 0; inline['$[['+k+']]']= buildinline (v, 20); }); } args = msg.content.split(/\s+/); switch(args[0]) { case '!isgreater': if (_.has(values,args[1])) { v1=values[args[1]]; d1=inline[args[1]]; } else { v1=parseInt(args[1],10); d1=v1; } if (_.has(values,args[2])) { v2=values[args[2]]; d2=inline[args[2]]; } else { v2=parseInt(args[2],10); d2=v2; } if( v1 &gt; v2 ) { sendChat('','Result('+d1+' &gt; '+d2+'): Success'); } else { sendChat('','Result('+d1+' &gt; '+d2+'): Failure'); } break; } }, registerEventHandlers = function() { on('chat:message', HandleInput); }; return { RegisterEventHandlers: registerEventHandlers }; }()); on("ready",function(){ 'use strict'; IsGreater.RegisterEventHandlers(); });
1410580684

Edited 1410580749
Gen Kitty
Forum Champion
Can you show me some examples of this, like you did your first script? I'll poke at this, and HB's card script again, over the weekend. I'm gaming in my friday game at the moment, so can only forum-browse :)
1410587941
The Aaron
Roll20 Production Team
API Scripter
There's no change to the inputs, though it looks better if you put bare numbers in brackets: [[23]]
1410633437
Gen Kitty
Forum Champion
I remember now what the issue was that i had. I want to be able to have powers with variable numbers of targets and put target names next to hit rolls or damage rolls, and I can't see any way of doing it. I've bounced the question off HB via PM, we'll see what happens.