This bit (line 66-69 in scorm_support.js) checks the value store but doesn't actually update it with new values:
//If cached value exists, return it
if(typeof value_store[property] !== "undefined"){
return value_store[property];
}
Line 190 checks if the returned value from the cache matches the value Captivate is trying to set:
if(!cached_value || cached_value !== value){
... but never updates the value store either.
This means that the value store will always contain the first value that was set, which in turn means that:
If e.g. cmi.location is set to "3", then "4", then "4" again, the second "4" won't be caught.
(more serious) If it's set to "3", then "4", then "3", the last value sent to the LMS will be "4" (because the last value Captivate tries to send matches the first value it sent, and so will be ignored).
Easy fix: Move the check for value equality from line 190 to the cmiCache function:
cmiCache = function(property, value){
var cachedValue;
//Ensure we have a valid property to work with
if(typeof property === "undefined"){ return false; }
//Replace all periods in CMI property names so we don't run into JS errors
property = property.replace(/\./g,'_');
cachedValue = value_store[property];
// ********* CHANGES START HERE ***************
//If cached value exists and is the same as new value, return it
if(typeof cachedValue !== "undefined" && cachedValue == value){
return cachedValue;
}
//Otherwise add to - or replace - in cache
if(typeof value !== "undefined"){
value_store[property] = value;
}
return false;
};
Since we now return false if the values don't match, we don't need the check in Captivate_DoExternalInterface:
if(cached_value === false) { // strict equality - could be an empty string
strErr = SCORM_API.SetValue(parameter, value);
setValueWasSuccessful = (strErr === "true");
} else {
...
This bit (line 66-69 in scorm_support.js) checks the value store but doesn't actually update it with new values:
Line 190 checks if the returned value from the cache matches the value Captivate is trying to set:
... but never updates the value store either.
This means that the value store will always contain the first value that was set, which in turn means that:
Easy fix: Move the check for value equality from line 190 to the cmiCache function:
Since we now return false if the values don't match, we don't need the check in Captivate_DoExternalInterface: