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] Unexpected token ":" while parsing string?

1519142284
Missingquery
Pro
Sheet Author
API Scripter
I am attempting to store Javascript objects in abilities on the character sheet, but when I try to extract the object from the string, I get the error in the title. Here is the relevant code: let SkillsA = findObjs({ characterid: attacker.id, type: "ability"}); for (var i in SkillsA){ SkillsA[i] = SkillsA[i].get("action"); //grabs the "macro text" of each ability } SkillsA = eval(SkillsA[0]); //gets the firstmost string in the list and parses it as code; this is where the error is thrown log(SkillsA); And here is the ability text: {     triggertime: 'during',     u_wepreq: 'none',     e_wepreq: 'none',     whotriggered: 'either',     radius_effect: 'none',     physmagcond: false,     u_healfactor: 0,     e_healfactor: 0,     u_hitmod: 0,     e_hitmod: 0,     u_critmod: 0,     e_critmod: 0,     u_avomod: 0,     e_avomod: 0,     u_ddgmod: 0,     e_ddgmod: 0,     physmag: true,     damagemod: 0.5 * Physmag,     u_stat_target: 'none',     e_stat_target: 'none',     u_stat_targetmod: 0,     e_stat_targetmod: 0,     children_skills: [] }; Note that I have been able to extract JSON objects from the abilities section before, though I am not using that method due to the fact that I have to reference the Physmag variable (with a value of 1), and as I understand it, such an expression would not be valid JSON.
1519142933
The Aaron
Pro
API Scripter
Generally speaking, eval() is considered to be the worst sort of bug inducing construct and security risk.  I'm surprised it actually exists in the sandbox at all.  I would have removed it, personally. What is the problem you're trying to solve here, maybe there is another way to make it work? 
1519143542

Edited 1519143576
Missingquery
Pro
Sheet Author
API Scripter
I'm trying to pass the entire string from the ability into the API script and convert it to an object so that I can use its various key values in a larger script, some of which may include variables that already exist within the API script (such as the Physmag variable). I've tried using JSON.parse() already, and JSON's stricter syntax for value expressions has been causing problems for me when referencing the aforementioned variables.
You could use the JSON (and physmag = true) if you change the damagemod attribute to 0.5 * (physmag ? 1 : 0)
1519143908
The Aaron
Pro
API Scripter
Marth Lowell said: I'm trying to pass the entire string from the ability into the API script and convert it to an object so that I can use its various key values in a larger script, some of which may include variables that already exist within the API script (such as the Physmag variable). I've tried using JSON.parse() already, and JSON's stricter syntax for value expressions has been causing problems for me when referencing the aforementioned variables. I'd read it as JSON, with the damagemod set to "0.5 * :PHYSMAG:" or similar and post process the keys into true values using a known set of mappings.