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

Reveal script confusion

1397066232

Edited 1397074133
I am teaching myself javascript and have an easy question. What part of this code do I enter the name of the object I want to reveal. It says to use .foo or .bar. I know these are variables used in programming jargon. Assuming I was using .ambush for the name of the token I want to reveal. I assume I change the name of the token to have .ambush in there somewhere. Where in the javascript do I put .ambush so it knows to look for a token with .ambush in it? Thanks in advance. I have been trying to figure it out for days now and I give up. var getByClasses = function(classes, criteria) { var graphics = findObjs({ _pageid: Campaign().get("playerpageid"), _type: "graphic", }); var cclasses = {}; for (var i = 0, il = classes.length; i < il; i++) { cclasses[classes[i]] = true; } var output = []; _.each(graphics, function(item) { var item_name = item.get('name'); if (criteria) { var matches_criteria = true; for (var clabel in criteria) { var cvalue = criteria[clabel]; if (item.get(clabel) != cvalue) { return; } } } var item_classes = item_name.match(/\w+/); _.each(item_classes, function(cclass) { if (cclasses[cclass]) { output[output.length] = item; } }); }); return output; } var getRandomByClasses = function(classes, criteria) { var items = getByClasses(classes, criteria); if (!items.length) { return; } var item = items[_.random(0, items.length-1)]; return item; } var getRandomByClass = function(klass, criteria) { return getRandomByClasses([klass], criteria) } var getByClass = function(klass, criteria) { return getByClasses([klass], criteria); } var processCommand = function(command, argv) { switch(command) { case '!reveal': case '!show': /* Usage: !reveal foo bar Result: will find all graphics with a name that contains .foo or .bar and then move them to the objects layer. This may be useful for ambushes, cutscenes, etc. */ _.each(getByClasses(argv), function(item) { item.set({ 'layer': 'objects' }); }); break; case '!conceal': case '!hide': /* Usage: !conceal foo bar Result: will find all graphics with a name that contains .foo or .bar and then move them to the gm layer. This may be useful for ambushes, cutscenes, etc. */ _.each(getByClasses(argv), function(item) { item.set({ 'layer': 'gmlayer' }); }); break; case '!revealrandom': case '!showrandom': // Usage: !revealrandom foo bar // Result: picks a random item with .foo or .bar in the name and shows var item = getRandomByClasses(argv, {'layer':'gmlayer'}); item.set({ 'layer': 'objects' }); break; case '!concealrandom': case '!hiderandom': // Usage: !revealrandom foo bar // Result: picks a random item with .foo or .bar in the name and hides var item = getRandomByClasses(argv, {'layer':'objects'}); item.set({ 'layer': 'gmlayer' }); break; case '!alter': case '!change': // Usage: !alter foo bar > rotation=24.1 aura1_radius=5 aura1_color="#44FF00" // Result: changes properties of all graphics with .foo or .bar // Note that this is not a proper parser, so you need to keep it to // a single space, don't forget the '>' character to separate the // classes from the properties, and put quotes around strings. // Additionally, don't put spaces in values, as it will not work. var classes = []; var alterations = []; var found = false; for (var i = 0, il = argv.length; i < il; i++) { var klass = argv[i]; if (klass == '>') { found = true; continue; } if (!found) { classes[classes.length] = klass; } else { alterations[alterations.length] = klass; } } alterations = alterations.join(' '); log(alterations); eval('var changes = ' + alterations); log(changes); _.each(getByClasses(classes), function(item) { item.set(changes); }); break; } } on("chat:message", function(msg) { var argv = msg.content.split(' '); var command = argv.shift(); if (msg.type != 'api') { return; } log(msg.content); return processCommand(command, argv); });
Looks like it's just a parameter, actually. He's using foo and bar as examples only. So rather than calling "!reveal foo bar", it seems like you should be able to just say "!reveal ambush" if that's what you named your objects. Here's where he does that: var argv = msg.content.split(' '); var command = argv.shift(); He takes all the words you entered and then pulls the first one out as the command. The rest are stored as arguments, which he references in each command's code as getByClasses(argv). getByClasses then uses those arguments to find your objects. PS. You can format code on this site by clicking on the first formatting button. :)