pipwerks/Captivate-Publishing-Templates-Redux — Issue #1: cmiCache value store is never updated
Author: TheKaneda
Created: 2012-02-02 11:00:26+00:00
State: open

This bit (line 66-69 in scorm_support.js) checks the value store but doesn't actually update it with new values:

```javascript
//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:

```javascript
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:
1. If e.g. cmi.location is set to "3", then "4", then "4" again, the second "4" won't be caught.
2. (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:

```javascript
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:

```javascript
if(cached_value === false) { // strict equality - could be an empty string

strErr = SCORM_API.SetValue(parameter, value);
setValueWasSuccessful = (strErr === "true");

} else {
...
```