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] First try of one-click script

1574194172

Edited 1574194259
Alain H.
Pro
Sheet Author
API Scripter
Hello, I have a problem that I can't solve. I'm not an expert in javascript, if anyone could help me. Thank you in advance. <a href="https://gist.github.com/Zakarik/9c388836b7f4ff6b16468386238345b0" rel="nofollow">https://gist.github.com/Zakarik/9c388836b7f4ff6b16468386238345b0</a> Error : TypeError: Cannot read property 'Toute Page' of undefined TypeError: Cannot read property 'Toute Page' of undefined at Object.checkInstall [as CheckInstall] (apiscript.js:12:15) at apiscript.js:119:20 at eval (eval at &lt;anonymous&gt; (/home/node/d20-api-server/api.js:154:1), &lt;anonymous&gt;:65:16) at Object.publish (eval at &lt;anonymous&gt; (/home/node/d20-api-server/api.js:154:1), &lt;anonymous&gt;:70:8) at checkForReady (/home/node/d20-api-server/api.js:1441:12) at /home/node/d20-api-server/api.js:1521:9 at c (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:14:64) 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)
1574195315
GiGs
Pro
Sheet Author
API Scripter
some more information would be appreciated. What is the script meant to do, and is it for a specific sheet? Though this might be the ussie: the error suggests checkinstall is where its failing, and that says var checkInstall = function() { &nbsp; &nbsp; &nbsp; &nbsp; var gc = globalconfig &amp;&amp; globalconfig.knightstylemarker; allPage = gc['Toute Page']; &nbsp; &nbsp; }; globalconfig is never defined anywhere, so the var gc line will cause an error.
1574195483
Alain H.
Pro
Sheet Author
API Scripter
The script is supposed to add markers on players' tokens when an attribute is changed on their character sheet. It's for Knight's sheet. And for globalconfig, there is a checkbox in parameter for the script, I tried to get the value (true or false), but I wasn't sure how to proceed. How do I do this?
1574197025

Edited 1574198300
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Hmm, also, looking at that checkinstall that GiGs highlighted, I see another problem: var checkInstall = function() { &nbsp; &nbsp; &nbsp; &nbsp; var gc = globalconfig &amp;&amp; globalconfig.knightstylemarker;//This is going to resolve to a boolean, not an object; or undefined if one of these is undefined.. //EDIT: My above issue is actually not an issue as Aaron, the great scriptomancer, has pointed out to me via backchannels. allPage = gc['Toute Page'];//This expects gc to be an object. &nbsp; &nbsp; }; Now, as you pointed out globalconfig is how scripts access the one-click options. However, the way this script is trying to access them is incorrect. That line needs to be rewritten as: var checkInstall = function() { &nbsp; &nbsp; &nbsp; &nbsp; var gc = globalconfig.knightstylemarker||"need to add a default"; allPage = gc['Toute Page']; &nbsp; &nbsp; }; Note, that I think you are also looking for the globalconfig file incorrectly. I haven't used global configs myself, but I believe that the property name for a given script's configs is the same as the js file name. So, for Knight Style Markers, it'd be globalconfig['Knight Style Marker'] instead of globalconfig.knightstylemarker. I'd see if the script's author is active anywhere and message them there about the issue. Unfortunately, I don't recognize the github handle, so I can't direct you to a Roll20 account to contact. EDIT: And just realized you are the author after I relooked at the script.json.
1574197133

Edited 1574197228
GiGs
Pro
Sheet Author
API Scripter
I've never installed a script to library, but having a quick look at other scripts, it looks like you should put this at the very start of the script var globalconfig = globalconfig || undefined ; You need a variable in the script to hold the values set in useroptions. Edit: &nbsp;Scott's answer is more comprehensive. I'm not sure either that you are grabbing the values correctly. I'd look through the script library for others that are using options and see how they did it.
1574197203
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
I'd probably recommend avoiding naming your in script global config holder the same as globalconfig. That could lead to some problems.
1574197385
GiGs
Pro
Sheet Author
API Scripter
I took that line directly from a script that was in the library, but you're right, it's probably a good idea to use a unique name.
1574197631

Edited 1574198688
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Yep, I know you did. Was just adding my two cents about what the best practice should probably be. EDIT: Also, note a change in my comments on the code in my first reply. Aaron corrected me on some JS basics.
1574598490

Edited 1574598527
Alain H.
Pro
Sheet Author
API Scripter
Thanks for the help. I'm trying to understand how it works, being a relative beginner in javascript, I'm more used to other languages. I tried to follow the advice, by doing this: var checkInstall = function() { var gc = global['Knight Style Marker']; allPage = gc['Toute Page']; }; and I added that: var global = globalconfig || undefined; I'm not sure about myself, what do you think? And for that: var gc = globalconfig.knightstylemarker||"need to add a default"; I'm not sure what to put "need to add a default". In my useroption, the default setting of the only option there is is True. Again, thank you for helping me understand and progress in javascript.