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 Interpreting Error Reporting

While it is more likely that I have a programming error, the following problem has cropped up after the One Click install. It would be very helpful any gurus could help me parse the following error report. The script creates characters for a science fantasy RPG.&nbsp; TypeError: Cannot read property 'set' of undefined at apiscript.js:846:16 at Function._.each._.forEach (/home/node/d20-api-server/node_modules/underscore/underscore.js:153:9) at setSomething (apiscript.js:831:7) at apiscript.js:1220:25 at eval (eval at (/home/node/d20-api-server/api-dev.js:105:34), :65:16) at Object.publish (eval at (/home/node/d20-api-server/api-dev.js:105:34), :70:8) at /home/node/d20-api-server/api-dev.js:1163:12 at /home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:560 at hc (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:39:147) at Kd (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:546) So I reading this that the function setSomething has a TypeError due to an undefined value. This is being called from line 1220 of the api script expgame. Is there more that I should be understanding from this? If I am understanding this correctly then then a more cogent question will follow. Thanks. The whole pile of code is here <a href="http://pastebin.com/5v2Qq9fF" rel="nofollow">http://pastebin.com/5v2Qq9fF</a>
1457838389
The Aaron
Pro
API Scripter
Line 846: &nbsp;you never check to see if the oHealth object exists. If the character doesn't have the attribute you're looking for, it will error. If a token exists but doesn't represent a character, you'll probably have a similar problem.&nbsp;
It had to do with asynchronous (I think). I used setTimeout to delay things a bit before hitting the set function. My guess is that it was getting to the set function before oHealth existed. Hard for me to say. Still working after dozens of test runs. Preceding the setTimeout zero success.&nbsp; Thanks!
1457927600
The Aaron
Pro
API Scripter
Hmm. &nbsp;Using a timeout method like that is... suboptimal. Is there some reason you can't just do the set in the callback for the .get('bio',...) ? &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CON_holder&nbsp;=&nbsp;""; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _.each(selected,&nbsp;function(obj)&nbsp;{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;(obj._type&nbsp;!=&nbsp;"graphic")&nbsp;{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;}; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;var&nbsp;oToken&nbsp;=&nbsp;getObj("graphic",&nbsp;obj._id); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;var&nbsp;oCharacter&nbsp;=&nbsp;getObj("character",&nbsp;oToken.get("represents")); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oCharacter.get("bio",&nbsp;function(bio)&nbsp;{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CON_holder&nbsp;=&nbsp;bio; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;(CON_holder&nbsp;===&nbsp;null)&nbsp;{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CON_holder&nbsp;=&nbsp;""; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;}; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CON_holder&nbsp;=&nbsp;CON_holder&nbsp;+&nbsp;anthro_info[chosen].comments&nbsp;+&nbsp;"&lt;br&gt;"; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oCharacter.set("bio",&nbsp;CON_holder); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;}); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;})
Thanks so much for this. I will plug this in and see how it goes. Then I will try and figure it out. Callbacks are still a challenge for this beginning programmer. ;) I will let you know how it goes. &nbsp;
1457984221
The Aaron
Pro
API Scripter
No problem. =D &nbsp;Callbacks are hard for us experienced programmers as well! &nbsp;Feel free to ask me anything if you need help, or even just want to discuss how something works, or why to do it one way or another, or whatever. =D
I will do. I certainly am blown away by the fluidity and flexibility of js.Comprehension is required to make things work. ;) This is the most fun way to learn a language ever. I bought an Udemy course called Javascript Understanding the Weird Parts. Once through this I hope to approach Crockford's book on Javascript again. There is a huge lecture series by Crockford on YouTube I am salivating to watch.&nbsp; Your offer of help is appreciated.&nbsp;
1457989513
The Aaron
Pro
API Scripter
Cool! &nbsp;That saves me the trouble of recommending it. =D &nbsp;No worries, ping me anytime or just post in the forum and I'll likely see it pretty quickly. =D