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

[Sharing & Need Help] Double Cross TRPG Dice rolling API & Error Lock

1520912366

Edited 1520912830
Hey all, First of all, I have to admit that I have zero programming knowledge and I barely understand how API works. An API Scripter called Zetetic L. has created an API script for Double Cross TRPG. (Please refer to the attached source code, the scripter has agreed to share the source code to the community.) This game uses the d10 system. Out of all d10s rolled, the player will select the die with the highest number and that becomes the “achievement number” of that particular “skill-check”. Whenever the outcome of a particular die is greater than or equal to the critical value (By default: 10, the minimum critical value you can get is 2) is rolled out, a 10 will be automatically added to the “achievement number”. (Even If more than one die criticals during a roll, that count as one critical only. So 10 could be added to the “achievement number”) The player could then reroll all the "criticaled" dice again until it no longer Criticals. If the critical value happens to be 11, you can’t crit at all. (Since the maximum outcome you an get from a d10 is 10) You may refer to the following illustration from the English translation of the core rulebook: //To illustrate, lets say a player rolls three dice and gets a ten, ten, and a seven. The player has criticaled once and may re-roll two dice. The second roll comes up as a ten and three. The player has criticaled again and may re-roll one die. This next roll results in a five. Five is the player's Score and he gets a bonus of twenty for getting two Criticals. His resulting score is twenty-five.// The API works pretty well for calculating the “achievement number”. The only thing you’ll need to do is to type out what you’ll need in such format: !sr [Number of d10s]dx[critical value][+/-other adjustment] Say, you are going to roll 3d10s, the critical value is 2 and for some reason you also get a +2 adjustment. You'll input: “!sr 3dx2+2” in the chat room, then you will receive something like this: 3dx2+2 → 10[6, 8, 2] + 10[7, 7, 7] + 10[8, 5, 5] + 10[10, 6, 9] + 10[7, 3, 1] + 10[5, 1] + 10[6] + 10[9] + 10[5] + 10[3] + 1[1] +2 → 103 Looks cool right? But there’s something missing…...Yeah, it couldn't handle wrong inputs. For instance, if you try to input “!sr 3dx!” to the chatroom, the whole api sandbox would crash and you’ll have to restart it again. The API Output Console would say something like this: //Your scripts are currently disabled due to an error that was detected. Please make appropriate changes to your scripts and click the "Save Script" button and we'll attempt to start running them again. // As far as I know, this is called the “error lock” and I am incapable of solving it (not unless I restart the sandbox everytime someone screwed up). I would greatly appreciate it if someone could help me out... ----------------------Source code--------------------------------- <a href="https://gist.github.com/MeowLKW/28b3f372740b73c56c666e82ba7a7bdc" rel="nofollow">https://gist.github.com/MeowLKW/28b3f372740b73c56c666e82ba7a7bdc</a>
1520914828

Edited 1520916600
GiGs
Pro
Sheet Author
API Scripter
The non-programming way to handle this would be to make a macro to launch the script, and build the macro so it can only accept legal inputs. Something like !sr ?{Number of D10|1|2|3|4|5|6|7|8|9|10}dx?{Critical Value?|2|3|4|5|6|7|8|9|10}?{Plus or Minus|+|-}?{Modifier?|0|1|2|3|4|5|6|7|8|9|10} This will slow down running the macro significantly, but if you can replace some of those numbers with attribute calls, all the better: !sr @{selected|DiceRollStat}dx@{selected|CriticalValueStat}?{Plus or Minus|+|-}?{Modifier?|0|1|2|3|4|5|6|7|8|9|10} If you trust players to just enter numbers, you can get rid of the dropdowns which will be a lot quicker !sr ?{Number of D10}dx?{Critical Value}?{Plus or Minus|+|-}?{Modifier}
1520915815

Edited 1520916052
GiGs
Pro
Sheet Author
API Scripter
The specific error you described can be handled by this In the function dx, there is the line var match = /^(\d+)(dx)(\d|)(((\+|-)(\d+)|)((\+|-)(\d+)|))$/i.exec(triggermsg); //Algorithm [0]2dx8-2+10,[1]2,[2]dx,[3]8,[4]-2+10,[5]-2,[6]-,[7]2,[8]+10,[9]+,[10]10 Add the following immediately after that line: if(match === undefined || match === null || match.length &lt; 11) { &nbsp; &nbsp; return "input error, try again!"; } i dont know if this will catch every possible error. But it does fix the example you provided and a few others I tried.