[HELP] Card Decks - prev["_currentHand"] is always undefined.

1523883199

Edited 1523883666
I have used the on("change: event many times. I was always able to use the previous values (before the change) as well as the new values. I am now setting up a script that would be much more resource efficient if it could detect the difference between players re-arranging their cards and changing the cards they have. That is why I wanted to compare the hand they have now with the previous hand - but I always get the value of prev["_currentHand"] as undefined. is this a bug? am I doing something wrong? Here is my code, abridged. on("ready", function() {     "use strict";          on("change:hand", function(obj, prev) {                sendChat("CardsEquipment","/w gm Hand changed!");                                    var playerWithHand = findObjs({_type: "player", _id: obj.get("_parentid")})[0];         var charactersControlledByPlayer = findObjs({_type: "character", controlledby: obj.get("_parentid")});         [code hidden for forum post]         var currentHand = [];         var currentHandStringLeft = obj.get("_currentHand");         // prev["_currentHand"] is always undefined;         // log(currentHandStringLeft);                  log(obj.get("_currentHand"));         log(prev["_currentHand"]); [rest of code hidden from froum post]
1523902751

Edited 1523902868
The Aaron
Pro
API Scripter
With the recent changes to the API, the documentation is outdated: {    "obj": {       "currentHand": "-KYHr_xnaiqIPlhOVNjg,-KYHpZutcaghHAImMb-s,-KYHrOe-I9m1btsF7JWp,-KYHqDQ788vRkfP-61Em,-KYHqpDla6NaUP3qbKpv,-KYHr2TmQrmwab-20oW4,-KYHqyya9cD-0KBxb5ei,-KYVjSZkB9s2FwuomMS2,-KYViNRM0y_EG5d_HzTN,-KYVhihRnjfhmhTqG8f3,-KYVkRB1aeaa61_VULzu,-KYVgpI8Ww3cG_eyotyh,-KYVf5zGomKyLt2jtz77,-KYVkRB1aeaa61_VULzu,-KYVeXQSc13SoTnRRIDh",       "_type": "hand",       "_parentid": "-JS3qKxIUPHLzSbK24ve",       "_id": "-JcG5Jj8u7IYZiuPgTc4",       "currentView": "bycard"    },    "prev": {       "currentHand": "-KYHr_xnaiqIPlhOVNjg,-KYHpZutcaghHAImMb-s,-KYHrOe-I9m1btsF7JWp,-KYHr7nCDF-4CzvXLgtS,-KYHqDQ788vRkfP-61Em,-KYHqpDla6NaUP3qbKpv,-KYHr2TmQrmwab-20oW4,-KYHqyya9cD-0KBxb5ei,-KYVjSZkB9s2FwuomMS2,-KYViNRM0y_EG5d_HzTN,-KYVhihRnjfhmhTqG8f3,-KYVkRB1aeaa61_VULzu,-KYVgpI8Ww3cG_eyotyh,-KYVf5zGomKyLt2jtz77,-KYVkRB1aeaa61_VULzu,-KYVeXQSc13SoTnRRIDh",       "_type": "hand",       "_parentid": "-JS3qKxIUPHLzSbK24ve",       "_id": "-JcG5Jj8u7IYZiuPgTc4",       "currentView": "bycard"    } } Since currentHand is now writable, it has lost it's _.  Try: on("ready", function() {     "use strict";          on("change:hand", function(obj, prev) {                sendChat("CardsEquipment","/w gm Hand changed!");                                    var playerWithHand = findObjs({type: "player", id: obj.get("parentid")})[0];         var charactersControlledByPlayer = findObjs({_type: "character", controlledby: obj.get("parentid")});         [code hidden for forum post]         var currentHand = [];         var currentHandStringLeft = obj.get("currentHand");         // prev["currentHand"] is always undefined;         // log(currentHandStringLeft);                  log(obj.get("currentHand"));         log(prev["currentHand"]); [rest of code hidden from froum post] Incidentally, since the _ is optional on Roll20 objects, I highly recommend not adding it to avoid this sort of issue in future cases.  This wouldn't save you from the problem with the prev object, but I feel it's a good practice regardless.  Note that events still require the _, such as on('change:player:_online',...) (Edit: I updated the documentation for this case...  I'll try and look for other cases)
1523903133
Thank you :)