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

Hit my lunchtime limit.

1431544257

Edited 1431563945
I can't find the original script anymore but I've been messing around with a script called, "generate Cypher tables" off and on for a few months at lunch time. But first, what am I trying to do? I build up and tear down campaigns on an ever increasing tempo so figured that I could leverage this script to build my own rollable tables. And if I keep copyright material out of them I can share them since others may or may not find use for them. So simply put I want a script that I can run to build a whole bunch of rollable tables and macros for initial campaign setup. Nothing fancy, just grunt work. Create Color table, check to see if it exists already, success. Create Metals table, check to see if it exists already, success, ad nauseam... Figure if I get a good example I can build this up to my heart's content (at least during lunch) and one day have something useful. Right now I use a lot of Excel spreadsheets and want to move most of that over to scripts... This script works: (at least it did for me the past few days.) // To generate the table, type !generateCypherTable from chat. Looking to expand its functionality in time. on("chat:message", function(msg) { //Generates a new cypher when !generatecolors is entered if(msg.type == "api" && msg.content.indexOf("!generatecolors") !== -1) { // Create Table var table = findObjs({_type: "rollabletable", name: "colors"})[0]; if(table != undefined) { sendChat(msg.who, "Error: Color Table Already Exists!"); return; } table = createObj("rollabletable", { name: "colors", showplayers: false }); var tableId = table.get("id"); // Populate Table for(var i = 0; i < cyphers.length; i++) { var cypher = cyphers[i]; createObj("tableitem" , { _rollabletableid: tableId, name: cypher.name, avatar: "", weight: 1 }); } // Confirm Generation sendChat(msg.who, "Color table generated!"); } }); var cyphers = [ { "name": "Amber" }, { "name": "Black" }, { "name": "Blue" }, { "name": "Brown" }, { "name": "Clear" }, { "name": "Gold" }, { "name": "Gray" }, { "name": "Green" }, { "name": "Orange" }, { "name": "Pink" }, { "name": "Purple" }, { "name": "Red" }, { "name": "Silver" }, { "name": "Violet" }, { "name": "White" }, { "name": "Yellow" }]; While this one does not: Color Mutant V // To generate the table, type !generateCypherTable from chat. Looking to expand its functionality in time. on("chat:message", function(msg) { //Generates a new cypher when !generatecolors is entered if(msg.type == "api" && msg.content.indexOf("!generatecolors") !== -1) { // Create Table var table = findObjs({_type: "rollabletable", name: "colors"})[0]; if(table != undefined) { sendChat(msg.who, "Error: Color Table Already Exists!"); return; } table = createObj("rollabletable", { name: "colors", showplayers: false }); var tableId = table.get("id"); // Populate Table for(var i = 0; i < cyphers.length; i++) { var cypher = cyphers[i]; createObj("tableitem" , { _rollabletableid: tableId, name: cypher.name, avatar: "", weight: 1 }); } // Confirm Generation sendChat(msg.who, "Color table generated!"); table = createObj("rollabletable", { name: "metals", showplayers: false }); var tableId = table.get("id"); // Populate Table for(var i = 0; i < cypha.length; i++) { var cypha = cypha[i]; createObj("tableitem" , { _rollabletableid: tableId, name: cypha.name, avatar: "", weight: 1 }); } // Confirm Generation sendChat(msg.who, "Metals table generated!"); } }); var cyphers = [ { "name": "Amber" }, { "name": "Black" }, { "name": "Blue" }, { "name": "Brown" }, { "name": "Clear" }, { "name": "Gold" }, { "name": "Gray" }, { "name": "Green" }, { "name": "Orange" }, { "name": "Pink" }, { "name": "Purple" }, { "name": "Red" }, { "name": "Silver" }, { "name": "Violet" }, { "name": "White" }, { "name": "Yellow" }]; var cypha = [ { "name": "Copper" }, { "name": "Silver" }, { "name": "Gold" }, { "name": "Platinum" }]; I'm sure someone who codes can probably figure it out in a few seconds and if you can give me an example of how to keep just piling things into a scrip to create more and more tables: that'd be great. I did not write the original: I just mangled it for my own use. From what I can remember about coding in general I should be able to build "datasets" (for lack of a better word) and then use nested loops to run through them all and create them in succession. Knowing I can do that and knowing how to do that is the problem at this point.
1431564317
The Aaron
Pro
API Scripter
See if this works: // To generate the table, type !generateCypherTable from chat. Looking to expand its functionality in time. on("chat:message", function(msg) { "use strict"; var cyphers = [ { "name": "Amber" }, { "name": "Black" }, { "name": "Blue" }, { "name": "Brown" }, { "name": "Clear" }, { "name": "Gold" }, { "name": "Gray" }, { "name": "Green" }, { "name": "Orange" }, { "name": "Pink" }, { "name": "Purple" }, { "name": "Red" }, { "name": "Silver" }, { "name": "Violet" }, { "name": "White" }, { "name": "Yellow" }], cyphas = [ { "name": "Copper" }, { "name": "Silver" }, { "name": "Gold" }, { "name": "Platinum" }], table,tableId,i,cypher,cypha; //Generates a new cypher when !generatecolors is entered if(msg.type === "api" && msg.content.indexOf("!generatecolors") !== -1) { // Create Table table = findObjs({_type: "rollabletable", name: "colors"})[0]; if(table !== undefined) { sendChat(msg.who, "Error: Color Table Already Exists!"); return; } table = createObj("rollabletable", { name: "colors", showplayers: false }); tableId = table.get("id"); // Populate Table for(i = 0; i < cyphers.length; i++) { cypher = cyphers[i]; createObj("tableitem" , { _rollabletableid: tableId, name: cypher.name, avatar: "", weight: 1 }); } // Confirm Generation sendChat(msg.who, "Color table generated!"); table = createObj("rollabletable", { name: "metals", showplayers: false }); tableId = table.get("id"); // Populate Table for(i = 0; i < cyphas.length; i++) { cypha = cyphas[i]; createObj("tableitem" , { _rollabletableid: tableId, name: cypha.name, avatar: "", weight: 1 }); } // Confirm Generation sendChat(msg.who, "Metals table generated!"); } }); I think the issue in your original is the reuse of the variable cypha . I renamed the array cyphas , and did a few other minor cleanup things.
Cool, thanks it did work. I also see a fatal flaw that I made while finishing lunch: I had two scripts which were both triggered from the same execution statement. The original scriptwriter used cypher and for testing purposes I was duplicating the same statements but thought I got all of the changes with cypha. I should be able to continue adding to that: thanks again.
1431569127
The Aaron
Pro
API Scripter
No problem. =D I wrote a TableExport (and by extension, import) program a while back: <a href="https://app.roll20.net/forum/post/1144568/script-t" rel="nofollow">https://app.roll20.net/forum/post/1144568/script-t</a>... Might be useful.