I want to carry a couple of basic tests within LMSSetValue and LMSGetValue to see:
- whether the specified data element is supported; and
- whether it has the necessary read or write privileges
and then set the error code appropriately. This is a pretty minimal set of tests – I’m probably going to have to add some others later – but it’s a starting point. Here’s the code.
function LMSGetValue(varname) {
// not initialized or already finished
if ((! flagInitialized) || (flagFinished)) {
errorCode = '301';
return '';
}
// not implemented
if ( ! isSupported(varname) ) {
errorCode = '401';
return '';
}
// not readable
if ( ! dataElementRead ) {
errorCode = '404';
return '';
}
// otherwise, return the requested data
errorCode = '0';
return cache[varname];
}
// --------------------------------------------------------
function LMSSetValue(varname,varvalue) {
// not initialized or already finished
if ((! flagInitialized) || (flagFinished)) {
errorCode = '301';
return "false";
}
// not implemented
if ( ! isSupported(varname) ) {
errorCode = '401';
return 'false';
}
// not writeable
if ( ! dataElementWrite ) {
errorCode = '403';
return 'false';
}
// otherwise, set the requested data, and return success value
cache[varname] = varvalue;
errorCode = '0';
return "true";
}
The additions are pretty straightforward.
- Lines 9 to 13, and 37 to 41 check to see whether the data element specified by the SCO is actually implemented (if you remember, I’m currently supporting all of the mandatory data elements, but only two of the optional elements). If the data element isn’t supported, the error code is set to ’401′.
- Lines 15 to 19, and 43 to 47 test whether the data element is readable (for the LMSGetValue function) or writeable (for the LMSSetValue function) and, if it fails, sets error code ’404′ or ’403′ respecively.
Note that, if the functions are successful, the error code is set to ’0′ before exit to indicate success. According to the SCORM RTE specification, every call to an API function must result in the error code being set – whether it’s successful or not.
Next time, I’m going to step away from the main VSSCORM code and do some work on a test harness that will allow me to monitor the SCO-LMS communications in order to make sure that all of this is working.
You might want to take a look at this test wrapper:
http://pipwerks.com/2008/01/16/a-revised-scorm-api-wrapper/
I haven’t looked at this version, but he says that it is based on Claude Ostyn’s original code, which I have used. Too bad that Claude’s site is gone now. At one point I have archived off his site, but I’m not sure where it is now…
Thank you, Joe. I will certainly look into this.