simplify-scorm
simplify-scorm copied to clipboard
SCORM 1.2 - bug in function getCMIValue
Hi @gabrieldoty,
First off, cheers for this amazing package. You are genius!!
I wanted to point out a bug I have been getting from some SCORM packages that are running this code.
The following line in scormAPI.js https://github.com/gabrieldoty/simplify-scorm/blob/2f60c3c26d6f415f331e93c26dd84a4cb878f39e/src/scormAPI.js#L295
I get cannot read hasOwnPropery of undefined. Turns out, some SCORM packages would request to get value of random objective or interactions if there is no value with that ID.
I suggest the following fixes:
Change L295 to:
if (typeof refObject === 'object' && !refObject.hasOwnProperty(structure[i])) {
and change L300 - https://github.com/gabrieldoty/simplify-scorm/blob/2f60c3c26d6f415f331e93c26dd84a4cb878f39e/src/scormAPI.js#L300 to:
refObject = typeof refObject === 'object' ? refObject[structure[i]] : undefined;
This seems to work for nearly all the 50+ packages I have tested so far.
Again, awesome work on this and cheers!!!!
Good find!
While investigating this, I found that there is an ever bigger underlying problem that affects both 1.2 and 2004 APIs, where it is impossible to get the value of an interaction (or anything else that has a childArray). For example, window.API.LMSGetValue("cmi.interactions.0.type") will always return an error, even when there is data there.
I will look into this.
I pretty sure cmi.interactions.n.id and others are write only. Only the cmi.interactions._count is RO. So this is not bug, i guess..
cmi.interactions.n.type (“true-false”, “choice”, “fill-in”, “matching”, “performance”, “sequencing”, “likert”, “numeric”, WO) Which type of interaction is recorded
If you want to recover the interaction you need to use: cmi.interactions._children (id,objectives,time,type,correct_responses,weighting,student_response,result,latency, RO) Listing of supported data model elements
@xob any suggestions on how to quickly fix that? I have the same problem while executing window.API.LMSGetValue("cmi.objectives.0.id")