showQuestion and answerResult should only be used by developers given permission to use the Question Overlay.
Legends of Learning Platform: JavaScript API
The LoL Game API is implemented as a sequence of asynchronous calls between an iFrame parent and child. Use the browser's built in window.postMessage to send outgoing messages, and window.addEventListener("message", message => {...}) to receive messages. Details on each method are linked below.
// payload received (JSON stringified)
{
"welcome": "Welcome!",
"readyToPlay": "Are you ready to play?",
"greatJob": "Great job!",
"pressContinue": "Press the next button to continue.",
"onePlusOne": "One + One = Two"
}
window.addEventListener("message", function (msg) {
const { messageName, payload } = msg.data;
if (messageName === 'loadState') {
const previousState = JSON.parse(payload);
const currentProgress = previousState && previousState.currentProgress
const maximumProgress = previousState && previousState.maximumProgress
LoLApi('progress', {currentProgress, maximumProgress});
// do something with the data inside payload
break;
}
});
parent.postMessage({
message: 'loadState',
payload: '*'
},
'*');
complete
LoLApi('complete', {});
Code Example: Receiving Messages
const EVENT = {
RECEIVED: {
PAUSE: 'pause',
RESUME: 'resume',
QUESTIONS: 'questions',
LANGUAGE: 'language',
START: 'start',
INIT: 'init',
STATE: 'loadState'
}
};
window.addEventListener("message", function (msg) {
console.log('[PARENT => UNITY]', msg)
switch (msg.data.messageName) {
case EVENT.RECEIVED.PAUSE:
// Your PAUSE handler here
break;
case EVENT.RECEIVED.RESUME:
// Your RESUME handler here
break;
case EVENT.RECEIVED.QUESTIONS:
// Your QUESTIONS handler here
break;
case EVENT.RECEIVED.LANGUAGE:
// Your LANGUAGE handler here
break;
case EVENT.RECEIVED.START:
// Your START handler here
break;
case EVENT.RECEIVED.STATE:
// Your STATE handler here
break;
case EVENT.RECEIVED.INIT:
break;
default:
console.log('Unhandled message: ' + msg);
}
});