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

dynamically update state var

1482538082

Edited 1482538244
Is there a way to update state var dynamically?  I am trying to store character id numbers in a state var by I need to add and remove then as the party changes.   Here is move code: on("ready", function () {     "use strict";    if (!state.XP_Tracker) { state.XP_Tracker = {        Version: '0.1',        Config: {},        PoolIDs: {},        PoolCount: 0     }; }; log("XP Tracker Version " + state.XP_Tracker.Version + " is now ready."); }); AddTokentoXPPool = function (msg) {     var CharID = GetTokenCharID(msg);     _.each(CharID, function (Id) { // The line below is where I thing my problem is.  Id is a character id number.           state.XP_Tracker.PoolIDs[Id] = GetCharName(Id);         state.XP_Tracker.PoolCount++;     }); }
1482545820
The Aaron
Pro
API Scripter
That looks like reasonable code. Are you getting an error? You don't really need to store a count, you could get it easily with: _.keys(state.XP_Tracker.PoolIDs).length
Here is the error I am getting: Your scripts are currently disabled due to an error that was detected. Please make appropriate changes to your scripts and click the "Save Script" button and we'll attempt to start running them again. More info... For reference, the error message generated was: TypeError: Cannot set property '-KIoKi2e2AX4Bjk4NHOc' of undefined TypeError: Cannot set property '-KIoKi2e2AX4Bjk4NHOc' of undefined at apiscript.js:14701:38 at Function._.each._.forEach (/home/node/d20-api-server/node_modules/underscore/underscore.js:153:9) at AddTokentoXPPool (apiscript.js:14699:7) at apiscript.js:14848:29 at eval (eval at <anonymous> (/home/node/d20-api-server/api.js:144:34), <anonymous>:65:16) at Object.publish (eval at <anonymous> (/home/node/d20-api-server/api.js:144:34), <anonymous>:70:8) at /home/node/d20-api-server/api.js:1394: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)
<a href="https://github.com/mcstalker/roll20-api-scripts/blob/master/XP_tracker/XP_tracker.js" rel="nofollow">https://github.com/mcstalker/roll20-api-scripts/blob/master/XP_tracker/XP_tracker.js</a>
Thanks I found the problem. It is working on.
1482554658

Edited 1482554678
Lithl
Pro
Sheet Author
API Scripter
Michael S. said: TypeError: Cannot set property '-KIoKi2e2AX4Bjk4NHOc' of undefined This error is complaining that state.XP_Tracker.PoolIDs is not defined. Most likely, you created state.XP_Tracker during an earlier test of your script, and so now !state.XP_Tracker returns false, and your state setup code (where the PoolIDs property is created) isn't being run.
1482587991
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
I fully understand wanting to customize how things work, but have you looked at the two XP trackers already in the repository? Even if they don't do what you want, they may give you some ideas. my EasyExperience:&nbsp;<a href="https://github.com/Roll20/roll20-api-scripts/tree/master/EasyExperience" rel="nofollow">https://github.com/Roll20/roll20-api-scripts/tree/master/EasyExperience</a> Kasper's ExperienceTracker:&nbsp;<a href="https://github.com/Roll20/roll20-api-scripts/tree/master/ExperienceTracker" rel="nofollow">https://github.com/Roll20/roll20-api-scripts/tree/master/ExperienceTracker</a>
Yes I have and I am trying to make a better one. &nbsp;I would like mine to have more options including: automatically add XP to a known pool of characters. Allow you to select an NPC, remove the it from the map and add the xp to the member pool.&nbsp; give xp only to selected tokens or named character. track xp in the players character sheets and option to track in a hondout as well or instead. plus more to come. &nbsp; Really, I am having fun with coding for the fun of it. :)
1482611224

Edited 1482611337
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Sounds good, I'll note that EasyExperience does 1-3 and the first half of 4. Also, totally get the having fun coding it too, so don't take this as me saying you shouldn't do it.