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

Absolute noob needing help!

I'm not a well-versed programmer and have just about got to grips with building character sheets in html/CSS, but I'm finding the API side quite impenetrable and can't seem to get started. What I'm looking to achieve (initially) is: 1) When a roll button is clicked, create a pop-up asking for a bonus number and add the selected number to the number of d6s about to be rolled E.g. Roll button produces a roll of 4d6, but first asks for a bonus number. If the bonus number is set to 3 then 7d6 will be rolled. 2) Insert a 'Re-roll' link into every roll result that, when clicked, will repeat that roll but keep the dice that were 6s as 6s E.g. Roll produces 1,1,3,4,6,6,6. Player clicks 'Re-roll'. 4d6 are rolled and three 6s are added to the result. Please can anyone point me in a good direction to get started?
1599057330
timmaugh
Forum Champion
API Scripter
Hey, Rich! Welcome to the wonderful world of js coding and R20 scripting! Input I think the first thing to understand is that the API can't trigger a "pop up" or ask for user input (unless it filters that through the chat input or button interaction). So any prompt for user input is actually a roll query input into the front end of the user input (what is entered into chat). If it is important to keep the value separate from the base number of dice, you can feed it into a different parameter of your script and then let your script modify the base d6 based on your input: !rico --3 --?{Enter bonus amount...|0} This would assume that your script would add 3 and the result of the query (after you sanitize it), and roll that number of d6 for the user. Another option would be to let them use inline rolls, and then you roll the extra dice and add them to the die pool... !rico --[[3d6]] --?{Enter bonus amount...|0} In that case, you have to extract the roll from the result in the message object into some form you can modify (like an array), then push() your bonus dice into the result, too. Output You can structure the output as you see fit... using html div objects and inline css. If you want to include a button to reroll, you would need to (1) structure the target of the button to be an api call, and (2) create that interface to your script to catch the reroll command. For (1), the idea is: [Button Label](!api --args) ...or, if you're outputting html... <a style="any css here" href="!api --args">Button Label</a> As for (2), you need to structure the api call to be something your script will catch, and keep the data in a place where the script can reach. You have some options for that... a) command line for the button (in the script call) b) in the state variable c) in a particular attribute on the character sheet Of those, (a) is the cleanest, IMO. !rico --reroll --1|2|3|4|6|6|6 I'm expecting your script to parse that second argument on "|" and produce an array of values, for every non-six, replace the entry in the array with another roll of d6 (in place). In the end, you have replaced the non-6s with a new value, and you can do whatever you need to with the array (total it, output criticals, etc.). If your initial build of the rolled values ALSO worked with an array, at this point you have rejoined the logical structure of your code so you can hand off the array to your formatting and output processes to show you the HTML output the same as for the initial roll. Also, using this sort of command line for your input can also let you trap whether this is a reroll (is the first argument "reroll"?), so that if you wanted to limit the players' ability to reroll to just one time, you wouldn't output the reroll button if you were ALREADY processing a reroll. Logic vs Language That's the logic that I would suggest, but then it comes to the actual language and building the script. What's your comfort, there? There are some pretty good discussions on this forum (and in the wiki/documentation) about best practices, etc., so post back if you need some pointing in the right direction.
1599062103
GiGs
Pro
Sheet Author
API Scripter
Are you actually wanting to use the API? The first question can be done with a standard macro, no API needed. The second question cant be done without the the API, but if you are planning to make your sheet widely available, its best to keep API features as an option, not a requirement, because most people don't have Pro. A simple example of button for the first question could be: <button type="roll" name="roll_fourd6" value="/roll [[4+?{How many bonus dice?|0}]]d6"></button>
Thanks for the replies. Yes, I've now figured out the first one using html. Tim I'm afraid my level of expertise is waaaay lower than that! Basically where I'm at is that I've found my way to the API scripts page for the game in question and now cannot figure out *anything* about how to use it. I've got the roll template all sorted in the html - now need to come up with the API to insert a functional re-roll link into it. I appreciate this is probably asking for a hell of a lot of hand-holding, but anything you can advise to get me started (bearing in mind that the Roll20 API guides are gibberish to me at present) would be very much appreciated.
1599246703
timmaugh
Forum Champion
API Scripter
Utilizing the API is a matter of a couple of things... 1) navigating the Script page, and... 2) either building or obtaining the script to include in your game Script Page You should see a tab for every script you have installed in your game. The first tab is the Script Library, which is where you would get what people call the "1-click Install" scripts. Functionally, these are the same as any other script, they are just easier to install/maintain, and the code is hidden from you. You'd find these in the drop down. Also on the Script Library page is the "Restart API Sandbox" button. Your game runs in a "sandbox" of javascript functionality, and sometimes a script can break the sandbox (with an un-caught javascript error). When that happens, your scripts won't run anymore until you restart the sandbox. You can trigger a restart by clicking the button on this tab OR by clicking the "Save Script" button on any of the script tabs. Both will reboot the sandbox. (Note: you must have at least one player *in* your game for the sandbox to actually start up). At the bottom of the Script Library tab (and every other script tab, in fact) is the console . If your script needs to log information, this is where it will appear. So if someone needs you to "check the log" or "go to your console," this is what they are talking about. It will also show you if a script has thrown an error with some... generally...  impenetrable information of where to look to find the problem. After the Script Library tab come tabs for each of the scripts you have installed. They each have a name (arbitrary - except that you want to name a new script before you start dinking with it -- I've had bad experience with a new script propagating itself into tab after tab because I didn't give it a name... it was... weird). If you didn't get a script via the 1-click install, you can get it from the script repository on GitHub . In that case, you would need to copy and paste the entire javascript code from the raw rendering of the file into the tab for that script. Once you have done that... voila. You have the script installed and can use it however it's meant to be used. The code window of each script's tab is a development environment, meaning you can type into it and alter/add any javascript you want to add. Sometimes you'll discover an error and the owner of the script will say, "Thanks... I'll fix that in the next release. For now, you can change line such-and-such to this..." This is where you would do that. Building/Obtaining Scripts I just talked about the 1-click install and the GitHub repo. Sometimes people drop code into the forum or a Gist. Whatever it is, you can add it to a new script tab. If you want to write your own javascript code, instead... you can code right into a tab's code window, or work in a separate IDE and then copy/paste your code in. Notepad++ is free, as is Visual Studio (this is what I use)... but if you ask around, I'm sure you'll get some other recommendations, too. As for learning javascript, that's too broad to get into here. There are plenty of tutorials online to help bridge that knowledge, and then you can post in this forum for specific usage questions. People are more than happy to help. There are some YouTube videos (people often reference Nick Olivo's video tutorials ), so you might start there. There are a few really good write-ups in this forum of specific ways to make things happen on Roll20... if I can find some, I'll post back.