
Hi all, I'm brand new to the Roll20 API and javascript, so forgive me if this question seems a little thick.
I'm trying to create a function that will allow me to populate a number of tokens, adding an iteration number to each, with the option to roll new hp for each based on a hit_dice attribute. I've managed to create the new token and hand-copy over attributes from the base token, but I'd like to be able to automate the copying of attributes, so I don't have to hand enter every single possible token attribute. Here is my code so far:
Unfortunately, "baseObject.keys()" is not a valid function call for the Roll20 token object. Is there another way to get an array with all the attributes of an object? Or is there an altogether better way to go about implementing this? Thanks so much!
I'm trying to create a function that will allow me to populate a number of tokens, adding an iteration number to each, with the option to roll new hp for each based on a hit_dice attribute. I've managed to create the new token and hand-copy over attributes from the base token, but I'd like to be able to automate the copying of attributes, so I don't have to hand enter every single possible token attribute. Here is my code so far:
function(msg, ARGV) { var objectCount = ARGV.shift(); var baseObject = getObj('graphic', msg.selected[0]['_id']); var baseImage = baseObject.get('imgsrc'); baseImage = baseImage.replace("/med.png", "/thumb.png"); log(baseObject); var baseKeys = baseObject.keys(); for(var n = 0; n < objectCount; n++) { var newObject = createObj("graphic", { subtype:'token', pageid:baseObject.get('_pageid'), imgsrc:baseImage, represents:baseObject.get('represents'), layer:baseObject.get('layer') }); for(var i = 0; i < baseKeys.length; i++) { var key = baseKeys[i]; if(key.indexOf("_") != 0 && key.indexOf("imgsrc") != 0) { newObject.set(key, baseObject.get(key)); } } newObject.set('left', baseObject.get('left')+70*(n+1)); // TO DO: assign new name, assign new hp } };
Unfortunately, "baseObject.keys()" is not a valid function call for the Roll20 token object. Is there another way to get an array with all the attributes of an object? Or is there an altogether better way to go about implementing this? Thanks so much!