pipwerks / Captivate-Publishing-Templates-Redux

Replacements for Adobe Captivate's Publishing Templates; cleaned, modernized, with extra functionality
http://pipwerks.com/2012/01/11/cleaning-up-adobe-captivates-scorm-publishing-template-part-1-introduction/
14 stars 2 forks source link

cmiCache value store is never updated #1

Closed Jither closed 12 years ago

Jither commented 12 years ago

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:

  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:

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 {
    ...
pipwerks commented 12 years ago

good catch, thanks. try it now...

pipwerks commented 12 years ago

think it's fixed now.