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

Help with API scripting

October 21 (8 years ago)
So, I'm new to the javascript coding, so I don't know what mistake I made but, I've double checked to make sure I didn't have overly many {[( or )]}.  That said, the script I set up constantly returns an error of  SyntaxError: Unexpected identifier  .  I'm trying to set up an easy way for players in my game to roll for randomized loot without it taking up a full session if they manage to clear a large area (particularly when handling multiple areas the loot could be from, and rolling in multiple tables/ammount to determint type, specific, and number of items)

Here's the code I have, any one got any pointers on this, or know what's going wrong?

var LootRolls = {
Standard Home: [
event(1, "Nothing was found" ),
event(1, (var vegies = {
event(8, "[[1d8]] Pieces of bubblegum" ),
event(7, "[[1d6]] Pieces of candy" ),
event(6, "[[1d4]] Sweetrolls/Pastries" ),
event(5, "[[1d2]] Cram" ),
event(5, "[[1d3]] Canned Fruit/Vegies"),
event(5, "[[1d3]] Big Mac'n'Chesse"),
event(5, "[[1d3]] Dandy Buck Apples"),
event(5, "[[1d3]] Fancy Colt Snack Cakes"),
event(5, "[[1d3]] Insta Mash"),
event(5, "[[1d3]] Noodles"),
event(5, "[[1d3]] Potato Crisps"),
event(5, "[[1d3]] Sugar Apple Bombs"),
event(5, "[[1d3]] Chocolate Frosted Sugar Bombs"),
event(5, "[[1d3]] Yum Yum Deviled Eggs"),
event(4, "[[1d2]] Fresh Apple"),
event(4, "[[1d2]] Fresh Carrot"),
event(4, "[[1d2]] Fresh Pear"),
event(4, "[[1d2]] Fresh potato"),
event(4, "[[1d2]] Fresh Radish"),
event(4, "[[1d2]] Slop"),
event(3, "Package of Ant Nectar"),
event(3, "Package of Fire Ant Nectar"),
event(3, "Slice of Maresippi Quantum Pie"),
event(1, "A Blood Orange")
)
}
]
};
October 21 (8 years ago)

Edited October 21 (8 years ago)
The Aaron
Pro
API Scripter
Well...

Properties with spaces need to be quoted:
var LootRolls = {
"Standard Home": [

Unless you define it, event() is not a function that's defined by default, so you need to define it somewhere...
var event =function(number, values) { /* ... something ... */ };

You can't define variables inside an argument to a function with var, so...
var vegies = { /* ... */ };
You can't define an object without giving properties, so vegies would need to be an array, or you'd need to supply properties.
var vegies = [
  /* ... */
];

Putting that all together:
var event = function( number, values) {  /* not sure what this should do */ };

var vegies = [
    event(8, "[[1d8]] Pieces of bubblegum" ),
    event(7, "[[1d6]] Pieces of candy" ),
    event(6, "[[1d4]] Sweetrolls/Pastries" ),
    event(5, "[[1d2]] Cram" ),
    event(5, "[[1d3]] Canned Fruit/Vegies"),
    event(5, "[[1d3]] Big Mac'n'Chesse"),
    event(5, "[[1d3]] Dandy Buck Apples"),
    event(5, "[[1d3]] Fancy Colt Snack Cakes"),
    event(5, "[[1d3]] Insta Mash"),
    event(5, "[[1d3]] Noodles"),
    event(5, "[[1d3]] Potato Crisps"),
    event(5, "[[1d3]] Sugar Apple Bombs"),
    event(5, "[[1d3]] Chocolate Frosted Sugar Bombs"),
    event(5, "[[1d3]] Yum Yum Deviled Eggs"),
    event(4, "[[1d2]] Fresh Apple"),
    event(4, "[[1d2]] Fresh Carrot"),
    event(4, "[[1d2]] Fresh Pear"),
    event(4, "[[1d2]] Fresh potato"),
    event(4, "[[1d2]] Fresh Radish"),
    event(4, "[[1d2]] Slop"),
    event(3, "Package of Ant Nectar"),
    event(3, "Package of Fire Ant Nectar"),
    event(3, "Slice of Maresippi Quantum Pie"),
    event(1, "A Blood Orange")
];

var LootRolls = {
    "Standard Home": [
        event(1, "Nothing was found" ),
        event(1, vegies)
    ]
};

I speculate that's not exactly what you're wanting, and that possibly you've got the incorrect expectations based on a tutorial for some other sort of Javascript system.  One thing to be aware of is that programming the Roll20 API is much closer to writing Node.js modules than writing code in the browser.  You don't have the DOM or the same sort of event system that exists in a browser.
October 21 (8 years ago)

Edited October 21 (8 years ago)
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
putting your code into the Google Closure Compiler gives, "JSC_PARSE_ERROR: Parse error. '}' expected at line 2 character 9
Standard Home: ["

var LootRolls = {
Standard Home: [
event(1, "Nothing was found" ),

That said, I don't recognize the syntax that you are using there (I am admittedly not a coding master). Also, have you looked at The Aaron's Recursive Tables script. It's pretty much made for what you are trying to do by utilizing rollable tables.

Hope that helps,

Scott

EDIT: Haha, ninja'd by The Aaron. While he didn't mention the script, take a look at recursive tables, it might be just what you need.
October 21 (8 years ago)
Thanks, I'll have to do that, and didn't realize it wasn't like standard javascript...I was power cramming through that for 4ish hours to try and get scripting set up to help stream line my game, gave myself one heck of a head ache, if it were html or xml I'd have an easier time as I'm fluent (if rusty) in those 'code' languages, particularly in if/then and things like that, and could have made something happen with that, but i'll take a look at the recursive tables script, thanks again for the pointers yall :D
October 21 (8 years ago)
The Aaron
Pro
API Scripter
Yup.  Happy to help you learn the the environment.  Technically, it's completely standard Javascript, you're just looking at javascript in the browser environment. =D  If you look into tutorials on building Node.js modules, it transfers well.  The Roll20 API is event driven, see the wiki: https://wiki.roll20.net/API:Introduction
October 21 (8 years ago)

Edited October 21 (8 years ago)
Okay, so I tried the recursive tables thing, that didn't do what I needed, and that script fix you posted The Aaron, did fix the syntax error, but you were right, it doesn't seem to be doing what I needed.  Basicly what I need is a table, within a table, for example the following sittuation

Roll table button rolls table a
Table a is composed of tables b c and d
when table a resolves which table (b c or d) it then rolls on that table, before outputting the result

IE, more specific to what I was trying to code it would have been, eventually

Player rolls House Standard Loot which rolls into either
Vegies, Meats, Meds, Junk, Booze, Chems, Melee Weapons, Armor, Ranged Weapons, Shields, Ammo (with varying weights dependant on how 'rare' the grouping should be to find in a house)
Then after that it would roll based on that result, in the case of Vegies it would roll up one of 24 different possible outcomes (again weighted) and say what that outcome was and roll the number of items found from that outcome (if applicable).

Basicly, it's a thing for more modern/scavenger style games to allow randomized loot to be much more randomized, whilst also reducing the amount of time it takes for that kind of randomization to be done.

Also: your post just before this one didn't show up until a minute or two after this one The Aaron, and I do appreciate the help, I'm still very much so wet behind the ears with java, it's nothing like linux or cmd line codes, or that sorta thing that I've done in the past so it's like jumping into a lake head first at this point XD
October 21 (8 years ago)
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
How were you setting up your rollable tables for use with Recursive Tables?

As a generic example:

Table-A:
Entry : weight
[[1t[tableB] ]] : 1
[[1t[tableC] ]] : 1
[[1t[tableD] ]] : 1
Nothing : 1

Entering !rt [[1t[Table-A] ]] into chat would then roll on table A and then expand the inline roll of the appropriate table.
October 21 (8 years ago)
The Aaron
Pro
API Scripter
Lesson 1: javascript !== java  =D
October 21 (8 years ago)

Edited October 21 (8 years ago)
Ada L.
Marketplace Creator
Sheet Author
API Scripter
Looks like someone else is running a Fallout: Equestria game. :)

For us to have a better understanding of what you're trying to do, it would also help to know what your event(number, message) function is intended to do. Is the number parameter supposed to be some sort of index for probability distribution? Is it a probabilistic weight?

You could possibly also leverage the VTT's rollable tables from the API, since then you can modify the rollable content without needing to modify the script each time.
October 22 (8 years ago)
Thanks for the response, but I did get it sorted by nesting tables into a set of weighted command rolls for randomized loot, it's still only low level, but it does do the job fairly well, I'll likely try to export the tables some time, to help save some time should any one else need them.