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 setting attribute values

I have been banging my head against the well trying to get this to work. This is the beginning of a script which will handle auto calculation for things that can't be calculated with normal equations. // Ensure fatigue_skillgrade exists on("add:character", function(obj) { createObj('attribute', { name: 'fatigue_skillgrade', characterid: obj.id, current: 'Standard' }); }); // Actually change values (will be dependent on fatigue value once I get past this problem) on("add:attribute", function(obj) { var attributeName = obj.get("name"); if (attributeName == "fatigue") { var fatigueSkillGrade = findObjs({_type: 'attribute', _characterid: obj.get('_characterid'), name: 'fatigue_skillgrade'})[0]; log(fatigueSkillGrade); fatigueSkillGrade.set({current: 'Hard'}); //fatigueSkillGrade.set('current', 'Hard'); // Same problem log(fatigueSkillGrade); } }); Everything seems to work okay if the line setting current for fatigueSkillGrade is commented out. You can see in the first two lines of output that the value actually does change but it throws an error anyway. If anyone sees a problem in the code please let me know. This is the output I get: {"name":"fatigue_skillgrade","current":"Standard","max":"","_id":"-JeRvnLoYq5emnTZHNsJ","_type":"attribute","_characterid":"-JeRvJJD3aVtI_fY_VbC"} {"name":"fatigue_skillgrade","current":"Hard","max":"","_id":"-JeRvnLoYq5emnTZHNsJ","_type":"attribute","_characterid":"-JeRvJJD3aVtI_fY_VbC"} /home/symbly/www/d20-api-server/node_modules/firebase/lib/firebase-node.js:1 orts, require, module, __filename, __dirname) { function f(a){throw a;}var j=v ^ Error: Firebase.child failed: First argument must be a non-empty string and can't contain ".", "#", "$", "[", or "]". at Error (<anonymous>) at Ha (/home/symbly/www/d20-api-server/node_modules/firebase/lib/firebase-node.js:12:204) at G.W.H (/home/symbly/www/d20-api-server/node_modules/firebase/lib/firebase-node.js:126:213) at TrackedObj._doSave (
1419975826
The Aaron
Pro
API Scripter
See if this works: // Ensure fatigue_skillgrade exists on("add:character", function(obj) { createObj('attribute', { name: 'fatigue_skillgrade', characterid: obj.id, current: 'Standard' }); }); // Actually change values (will be dependent on fatigue value once I get past this problem) on("add:attribute", function(obj) { var attributeName = obj.get("name"); if (attributeName == "fatigue") { setTimeout(function() { var fatigueSkillGrade = findObjs({_type: 'attribute', _characterid: obj.get('_characterid'), name: 'fatigue_skillgrade'})[0]; log(fatigueSkillGrade); fatigueSkillGrade.set({current: 'Hard'}); //fatigueSkillGrade.set('current', 'Hard'); // Same problem log(fatigueSkillGrade); },100); } });
Hi The Aaron. Gave your code a shot and I'm still seeing the same issue.
1419979103
Steve D.
Sheet Author
API Scripter
Sounds like the same problem I had when I was trying to edit attributes for the EotE character sheet. The problem I ran into was if I tried creating a new character in game and then adding preset attributes with the API, I couldn't change the value with the API until I refreshed the browser. I knew the attributes were there but the system kept throwing an error. Try adding this code below. createObj = function() { //Create Object Fix - Firebase.set failed var obj = createObj.apply(this, arguments); var id = obj.id; var characterID = obj.get('characterid'); var type = obj.get('type'); if (obj && !obj.fbpath && obj.changed) { obj.fbpath = obj.changed._fbpath.replace(/([^\/]*\/){4}/, "/"); } else if (obj && !obj.changed && type == 'attribute') { //fix for dynamic attribute after character created in game // /char-attribs/char/characterID/attributeID obj.fbpath = '/char-attribs/char/'+ characterID +'/'+ id; } return obj; }
1419979268
Lithl
Pro
Sheet Author
API Scripter
Hm, I thought the create->modify issue with fbpath was fixed a while ago...
Hi Steve D., I added your code and it's throwing a "RangeError: Maximum call stack size exceeded" error. After commenting out various parts it seems to be the following line: var obj = createObj.apply(this, arguments); Sorry, I have worked with some javascript but it's not my strongest language, not sure exactly why it would cause that error. Current script just to make sure I'm not being really dumb: <a href="http://pastebin.com/39VJmLmu" rel="nofollow">http://pastebin.com/39VJmLmu</a>
1419982986
Steve D.
Sheet Author
API Scripter
Try this code. I changed the function name to not be the same of createObj() createObjFix = function() { //Create Object Fix - Firebase.set failed var obj = createObj.apply(this, arguments); var id = obj.id; var characterID = obj.get('characterid'); var type = obj.get('type'); if (obj && !obj.fbpath && obj.changed) { obj.fbpath = obj.changed._fbpath.replace(/([^\/]*\/){4}/, "/"); } else if (obj && !obj.changed && type == 'attribute') { //fix for dynamic attribute after character created in game // /char-attribs/char/characterID/attributeID obj.fbpath = '/char-attribs/char/'+ characterID +'/'+ id; } return obj; } // Ensure fatigue_skillgrade exists on("add:character", function(obj) { createObjFix ('attribute', { name: 'fatigue_skillgrade', characterid: obj.id, current: 'Standard' }); }); // Actually change values (will be dependent on fatigue value once I get past this problem) on("add:attribute", function(obj) { var attributeName = obj.get("name"); if (attributeName == "fatigue") { var fatigueSkillGrade = findObjs({_type: 'attribute', _characterid: obj.get('_characterid'), name: 'fatigue_skillgrade'})[0]; log(fatigueSkillGrade); fatigueSkillGrade.set({current: 'Hard'}); //fatigueSkillGrade.set('current', 'Hard'); // Same problem log(fatigueSkillGrade); } });
Bingo!, that does the trick. Thanks so much. Eventually this will make its way into some scripts to go with the CoC 7th Ed and Runequest 6 sheets. I was afraid I would have to give up on auto-calculating everything. Based on what Brian was saying I'm guessing this is a regression bug?
1419988724
Steve D.
Sheet Author
API Scripter
Great!!
1419995987
The Aaron
Pro
API Scripter
Wow, nice job figuring that out Steve! I poked at it a bit earlier and was about to post my apologies for not figuring it out!