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 .
×
Advertisement Create a free account

API Logic and Libinline Help

1631547118
So perhaps I'm just really stupid, but I don't fully understand how to use these scripts in the following format. I'm running a Cyberpunk RED game, and I want to use these API's to do the following: 1. Make a 1d10 roll and get that rolls results, 2. If it is a 10, roll another 1d10, add it, and then add their skill bonus. 3. If it is a 1, roll another 1d10, subtract its results, and then add their skill bonus. I don't know how to trigger the scripts. I tried testing a few examples with checking simple rolls in chat messages and nothing happened. Also, I'd like to do one more thing. I'd like to make a macro that 1. rolls on a rollable table. 2. Then rolls 1d6 (secretly). 3. If that roll is 3 or more, then it rolls on 3 more rollable tables and displays them all in a chat table. Otherwise it just displays the result of the first rolled table. Is this possible, and how would I do these things?
1631575568

Edited 1631575696
timmaugh
Pro
API Scripter
Hey, Adam... Just to make sure I understand... You are describing a 2 step roll, correct? Not a 3 step. If the first roll is a 10, you effectively get: 10 + 1d10 + skill If the first roll is a 1, you get: 1 - 1d10 + skill I'm assuming that for a 2-9 you just add the skill... is that right? If so, you can do this: ![\][\]{&if [[1d10]].value = 10}10+1d10{&elseif $[[0]].value = 1}1-1d10{&else}$[[0]].value{&end}+@{selected|bar3}\]\]{&simple} Does that look like some of what you were trying? The above command line relies on APILogic and ZeroFrame. You need ZF because you are outputting a simple message at the end (so you can see it), and also because you have to defer the outer roll until APILogic handles the IF/ELSE. The outer roll is marked by: [\][\] ... \]\] So once APILogic puts together the right roll equation, that outer roll can execute. Now let me try your second question... EDIT: I used the selected token's bar3 as the "skill" just for the example, but you can replace that with what you actually need it to be. It can resolve with the Roll20 parsing (you don't have to use Fetch to get it "late"), so you can use a Roll20 syntax to get it.
1631576849
timmaugh
Pro
API Scripter
As for your second, here is a version that uses a roll template output, and rolls against the right number of tables. You'll want to change the header of the roll template and probably adjust to make sure you roll agains the right tables (I just rolled against the same "MaleNames" table over and over, to make it easy for you to spot where to change the command line)... but this: !&{template:default}{{name=Roll Proof of Concept}}{{First Table=[[1t[MaleNames]]]}}{&if [[1d6]].value >= 3}{{Second Table = [[1t[MaleNames]]]}}{{Third Table = [[1t[MaleNames]]]}}{{Fourth Table = [[1t[MaleNames]]]}}{&end}{&simple} ...produces an output like this if you roll a 3 or better: ...and an output like this if you roll a 1 or 2: Is that what you were looking for? This solution also requires APILogic and ZeroFrame.
Sounds like you're running into a problem I had a while back with the API.  The problem is that from inside the API , die rolls made to the chat window using sendChat() are detached background tasks.  The only way to guarantee capture of the returned value from the chat message is from within the callback function you need to send as an argument in sendChat(): sendChat('', rollStr, function (r) { let roll = JSON.parse(r[0].content); let rollVal = String(roll.total); /* Do whatever other processing you might need here, _within_ the callback function */ }); // end sendChat with callback Here, rollStr is a character string containing the "/r ..." chat command, and the callback function is simply declared inline (function (r) {}), and r will be replaced with the roll callback object from sendChat(), which is more completely documented with sendChat() itself. 
1631595094
Ok Timmaugh, I tried your solutions for the tables and it worked, but I realize I need something slightly different. So I think I need something that does the following: 1. Rolls on a random table. If that roll produces a specific result from the table (a specific string), then it outputs a second line with pre-written text. 2. If it produces anything other than that specific result, it then rolls 1d6. If that roll results in a 3 or greater, then it rolls on the other 3 tables and creates lines for them. 3. If that 1d6 roll is a 1 or 2, then it outputs a second line with pre-written text. So I'd write it like this, using your example, but I feel like I'm misunderstanding the structure. !&{template:default} {{name=Roll Proof of Concept}} {{First Line=[[1t[MaleNames]]]}} {&if $[[0]].value=Specific Result from Male Names Table} {{Second Line=Text}} {&else} {&if [[1d6]].value >= 3} {{Second Line= [[1t[MaleNames]]]}} {{Third Line= [[1t[MaleNames]]]}} {{Fourth Line= [[1t[MaleNames]]]}} {&else} {{Second Line=Text}} {&end} {&simple} Thank you for your help!
1631621548
timmaugh
Pro
API Scripter
That's pretty close. It looks like you're just missing a closing {&end} tag. Every IF requires an END, and each END closes the most recent open IF. So the END right before your SIMPLE closes the 1d6>=3 check, but that should be embedded in the larger check, for the specific return from your first table, so that END tag follows after. Also, when one side of your comparison might include space, you have to enclose that side in single quotes, double quotes, or tick marks (options provided in case your string already contains some of those characters). That matters if the "Specific Result from Male Names Table" would, in fact, include spaces. In the end, you'd end up with something more like: !&{template:default} {{name=Roll Proof of Concept}} {{First Line=[[1t[MaleNames]]]}} {&if $[[0]].value="Specific Result from Male Names Table"} {{Second Line=Text}} {&else} {&if [[1d6]].value >= 3} {{Second Line= [[1t[MaleNames]]]}} {{Third Line= [[1t[MaleNames]]]}} {{Fourth Line= [[1t[MaleNames]]]}} {&else} {{Second Line=D6 was 1 or 2}} {&end}{&end} {&simple}
1631632984
Oh my god! A second END tag and quotes, it's that simple... Thank you, that worked! I tweaked it a little more cause my intentions are evolving as I make this macro, but I got it working now that I know what I was doing wrong!
1631636958
timmaugh
Pro
API Scripter
Excellent! Post back if you hit more roadblocks.