Begin with H5P

Forums: 

Hi everybody,
I would like to work with H5P, but I don't understand how to use xAPIEvent. Could you help me, please?
I work on Drupal 8 and Opigno 2. 

H5P.externalDispatcher.on('xAPI', function (event) {
  console.log(event.data.statement);
});

When I would use the last function, I have an error, on the statement .on whose is not define.
I get this function on the documentation page of H5P: https://h5p.org/documentation/x-api

Why do I want to use this?
I need to build a module that gets the score of H5P exercise. I find this function who is interesting for me.

H5P.externalDispatcher.on('xAPI', function(event){
  if (event.getScore() === event.getMaxScore() && event.getMaxScore() > 0){
    console.log('do something useful here');
  }
});

I think I have a problem with my initialization, I use the following code to init my H5P variable. 

var H5P = window.H5P = window.H5P || {};

Thank's

Content types: 
otacke's picture

Hi!

Make sure that your script is running in the right context. Your script will have to run inside the iframe, and the best way to ensure that is by using the alter scripts hook to add your script as described in the dev docs.

Best,

Oliver 

Hi,

Thank's for your answer
I search in de Dev docs, but I don't find the alter script hook inside
But I see the HelloWord tutorial, to take my script I need to create a plugin for H5P/H5P library?
https://h5p.org/tutorial-greeting-card

otacke's picture

Hi!

Just have a look at https://h5p.org/drupal-customization

Best,
Oliver

Hi,

Thank's for your answer

I search on dev documentation, and I find this https://h5p.org/creating-your-own-h5p-plugin
So, to get the result at the end of H5P Excercise, I need to create a plugin?

Else I don't find how to using the alter script hook, and verify to work inside the iFrame

otacke's picture

Hi Killian! 

Just have a look at https://h5p.org/drupal-customization

Best,
Oliver

Thank's for your help, I succeed to take what I want ;)