• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Storing data in cmi.comments (SCORM 1.2 and JavaScript)

Engaged ,
Apr 12, 2013 Apr 12, 2013

Copy link to clipboard

Copied

Hi,

I have 50 numbers (technically an array) that I need to store so I can use them upon resuming a course. I can't save it in a Captivate variable in cmi.suspend_data because there are 50 scored interactions in the course, and I've found that I run into the space limit; the variable that comes back upon resume has often had much of it chopped off.

I decided to store the data in cmi.comments, but I've run into two problems. The first is that when I set cmi.comments in JavaScript, the course immediately quits. The code I'm using: g_objAPI.LMSSetValue("cmi.comments", randomNumbers); Is there something about cmi.comments that I don't understand (quite likely) which is causing this behavior? I'm testing on Scorm Cloud, and the log data looks like this:

[15:15:31.680] LMSSetValue('cmi.comments', '21,53,45,14,34,49,13,51,46,31,4,15,22,38,18,36,32,28,47,50,35,42,19,8,52,20,44,7,29,39,30,37,40,23,48,11,41,26,10,25,24,17,16,12,9,5,6,27,33,43') returned 'true' in 0 seconds 

[15:15:31.680] CheckForSetValueError (cmi.comments, 21,53,45,14,34,49,13,51,46,31,4,15,22,38,18,36,32,28,47,50,35,42,19,8,52,20,44,7,29,39,30,37,40,23,48,11,41,26,10,25,24,17,16,12,9,5,6,27,33,43, cmi.comments, , )

[15:15:31.680] Element is: comments

[15:15:31.680] Call is error free.

[15:15:31.680] StoreValue (cmi.comments, 21,53,45,14,34,49,13,51,46,31,4,15,22,38,18,36,32,28,47,50,35,42,19,8,52,20,44,7,29,39,30,37,40,23,48,11,41,26,10,25,24,17,16,12,9,5,6,27,33,43, cmi.comments, , )

[15:15:31.680] Element is: comments, storing at position 0

- [15:15:31.682] LMSCommit('') returned 'true' in 0 seconds 

[15:15:31.682] Checking for Commit Error

[15:15:31.682] Call is error free.

- [15:15:31.682] LMSFinish('') returned 'true' in 0.001 seconds 

[15:15:31.682] Checking for Finish Error

[15:15:31.682] Call is error free.

[15:15:31.683] Close Out Session

[15:15:31.683] Mode = normal

[15:15:31.683] Credit = credit

[15:15:31.683] CompletionStatus = incomplete

[15:15:31.683] SuccessStatus = unknown

[15:15:31.683] MasteryScore = 80

[15:15:31.683] Score = 0

[15:15:31.683] Sco was taken for credit

[15:15:31.683] Next entry is normal

[15:15:31.683] Session Time: PT1S (100 hundredths)

[15:15:31.683] Previous Time: PT0H0M0S (0 hundredths)

[15:15:31.683] New Total Time: PT1S (100 hundredths)

[15:15:31.683] New Tracked Total Time: PT26.10S

My second, related problem, comes if I try to reference cmi.comments in my code upon entering the first slide. It seems to do so before initializing, but of course I don't understand why:

- [15:03:09.9] LMSGetValue('cmi.comments') returned '' in 0 seconds 

[15:03:09.9] CheckForGetValueError (cmi.comments, cmi.comments, , )

[15:03:09.9] SCORM ERROR FOUND - Set Error State: 301 - GetValue called when not initialized. element-cmi.comments

- [15:03:09.11] LMSGetValue('cmi.comments') returned '' in 0 seconds 

[15:03:09.11] CheckForGetValueError (cmi.comments, cmi.comments, , )

[15:03:09.11] SCORM ERROR FOUND - Set Error State: 301 - GetValue called when not initialized. element-cmi.comments

- [15:03:09.12] LMSCommit('') returned 'false' in 0 seconds 

[15:03:09.12] Checking for Commit Error

[15:03:09.12] SCORM ERROR FOUND - Set Error State: 301 - Commit called when not initialized.

[15:03:09.12] Current status is not attempted so changing based on score

[15:03:09.12] Missing mastery score or raw score, setting to completed

- [15:03:09.12] LMSFinish('') returned 'false' in 0 seconds 

[15:03:09.12] Checking for Finish Error

[15:03:09.12] SCORM ERROR FOUND - Set Error State: 301 - Finished called when not initialized.

Any help would be appreciated, since I'm new to both JavaScript and manipulating SCORM. Thanks!

TOPICS
Quizzing and LMS

Views

3.7K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 15, 2013 Apr 15, 2013

Copy link to clipboard

Copied

Since you're modifying the SCORM code itself, it's difficult to determine the problem precisely.

For the first, it looks like maybe the cmi.comments store is ok - the set call is made, shows 'error free', and the set it made. Not sure why, however, the actual reported value is,

"StoreValue (cmi.comments, 21,53,45,14,34,49,13,51,46,31,4,15,22,38,18,36,32,28,47,50,35,42,19,8 ,52,20,44,7,29,39,30,37,40,23,48,11,41,26,10,25,24,17,16,12,9,5,6,27,3 3,43, cmi.comments, , )"

What's that extra "cmi.comments, ," at the end?

Then directly below that, you've got something calling LMSCommit and LMSFinish - so the course isn't just crashing...something is calling those two functions. Maybe the SCORM engine is robust enough to sense something is wrong and call those functions instead of crashing...?

Sure you're not overflowing the 4kb limit of the cmi.comments field with your string/list? I didn't try to count the characters.

Similarly for the second issue - if the lesson is calling for the cmi.comments before the API is initialized, then the order of your code is incorrect...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 15, 2013 Apr 15, 2013

Copy link to clipboard

Copied

Hm, I hadn't noticed it, but I don't know why that extra "cmi.comments" is at the end, either. When I restart the course and then call cmi.comments, only the numbers show up. Extraneous data also shows up at the end of cmi.suspend_data:

StoreValue (cmi.suspend_data, [lots of data here], cmi.suspend_data, , )

so I can only assume it is either something Captivate or SCORM Cloud is doing, not me.

Then directly below that, you've got something calling LMSCommit and LMSFinish - so the course isn't just crashing...something is calling those two functions. Maybe the SCORM engine is robust enough to sense something is wrong and call those functions instead of crashing...?

Sure you're not overflowing the 4kb limit of the cmi.comments field with your string/list? I didn't try to count the characters.

I figured the functions were somehow being called, but obviously I don't understand why. The string/list is 144 characters, which I didn't think would be too long to store... I can get all of the numbers back when I restart the course, so they're not getting truncated. I've also tried it with a single value -- g_objAPI.LMSSetValue("cmi.comments", 1); -- with the same result.

Similarly for the second issue - if the lesson is calling for the cmi.comments before the API is initialized, then the order of your code is incorrect...

Do you happen to know at what point the API is initialized for Captivate courses? I assumed it would initialize before any JavaScript on the first slide executed, but apparently that's not the case. I don't know how to change the order of what I'm doing; all I have is some code executing upon entering the first slide. This works:

var objCP = document.Captivate;

var randomNumbers = [];

if (objCP.cpEIGetValue("CPrandomNumbers") === '') {

for(i = 4; i < 54; i++) {

  randomNumbers[i-4] = i;

}    

var shuffle = function(array) {

  var m = array.length, t, j;

  while (m) {

  j = Math.floor(Math.random() * m--);

  t = array;

  array = array;

  array = t;

  }

};

shuffle(randomNumbers);

objCP.cpEISetValue("CPrandomNumbers", randomNumbers);

}

else {

  randomNumbers = g_objAPI.LMSGetValue("cmi.comments").split(',');
  objCP.cpEISetValue("storedComments", randomNumbers);

}

But this doesn't, and runs up against the initialization error:

var objCP = document.Captivate;

var randomNumbers = [];

if (typeof g_objAPI.LMSGetValue("cmi.comments") === 'undefined') {

for(i = 4; i < 54; i++) {

  randomNumbers[i-4] = i;

}    

var shuffle = function(array) {

  var m = array.length, t, j;

  while (m) {

  j = Math.floor(Math.random() * m--);

  t = array;

  array = array;

  array = t;

  }

};

shuffle(randomNumbers);

objCP.cpEISetValue("CPrandomNumbers", randomNumbers);

g_objAPI.LMSSetValue("cmi.comments", randomNumbers);
}

else {

  randomNumbers = g_objAPI.LMSGetValue("cmi.comments").split(',');

  objCP.cpEISetValue("storedComments", randomNumbers);

}

(CPrandomNumbers and storedComments are for my debug captions.)

Thanks!

Edited 2:41pm EST

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 17, 2013 Apr 17, 2013

Copy link to clipboard

Copied

Well, I've managed to get it working, somehow. I don't know what I did differently, but I started from scratch and kept fiddling. I did realize that cmi.comments starts as empty, not undefined, so I changed that. I don't know how I fixed setting the cmi.comments, since I'm using the same bit of code, but doing so no longer causes the course to quit.

I also found that despite my previous tests, cmi.suspended_data doesn't fill up completely if I save things in Captivate variables, so using cmi.comments probably wasn't even necessary! Doh. At least I learned quite a bit in the process, and this way I can easily read the string/list in the SCORM data, as opposed to Captivate's incomprehensible suspend data.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 17, 2013 Apr 17, 2013

Copy link to clipboard

Copied

That's terrific! I've been trying to find time to explore/duplicate what you're doing so I could answer with more than just theory...but you beat me to it. I think this is great - I know we'd like to store more custom data but never dug in... Nicely done!  I agree overall, better to use this comments field than suspend_data as, you say, it's already pretty convoluted...

Cheers!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 19, 2013 Apr 19, 2013

Copy link to clipboard

Copied

LATEST

It's an interesting thing to be able to do-- I've only just started exploring JavaScript and SCORM, and I'm enjoying learning more about it!

I will mention that one thing I noticed when using cmi.comments is that, for me at least, the values append themselves to data already in cmi.comments. For me this shouldn't be a problem, since I only write to cmi.comments once per student no matter how many times they resume, but it may complicate things slightly if you want to continuously write data to it. (I will need to make sure cmi.comments gets reset upon new attempts... hm~)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Help resources