xApi statements - getScore

Forums: 

Hi I'm attempting to use some h5p content types in Captivate and need to store some data such as score and completion status. I can see the xApi statements when I use the externaldispatcher and console.log(event.data.statement). However when I try to get something useful by doing console.log(event.getScore()) this returns null or nothing. I've tried to run this on both the arithmetic quiz and the question quiz. 

Any pointers on how I can get to what I need?

Thanks Jorgen

otacke's picture

Hi Jorgen!

What type of xAPI statement are you capturing (what "verb")? xAPI is about more than scores, and H5P makes use of a wider range of experiences that can be tracked. In general, only the statements where the verb property is "completed" will have a "result" property, and only the will getScore() return the actual score.

Best,
Oliver

Best,
Oliver

Hi Oliver and thanks for your reply! I finally managed to get what I needed from the statement without using the object method like so. Totally new to working with JSON so not sure if it's the best way though ;)

 if('result' in myJSON == true){        if('score' in myJSON['result'] == true){            cScore = myJSON['result']['score']['raw'];            cMaxScore = myJSON['result']['score']['max'];        }    }

 

 

otacke's picture

If you want exactly that behavior, I'd have gone for

if (myJSON.result && myJSON.result.score) { 
  cScore = myJSON.result.score.raw;
  cMaxScore = myJSON.result.score.max;
}

Best, Oliver

Awesome, thank you!!