Question Overlay (V4) [NOT REQUIRED]
Questions + Answers for API V4
The ShowQuestion method instructs the LOL Platform to display an overlay with a question from the LOL question bank. Game play is cannot continue until the answer result is received and the overlay is dismissed.
Register an event delegate or listener to handle the AnswerResultReceived event. This event indicates that the question overlay has been dismissed so that game play can continue.
The AnswerResultReceived payload contains a single JSON key value pair indicating whether or not the question was answered correctly, or if the overlay was dismissed without an answer.
{ "isCorrect": "true" } // The answer was correct
{ "isCorrect": "false" } // The answer was incorrect
{ "isCorrect": null } // The overlay was dismissed with no answer
// Show Question (trigger overlay)
window.postMessage({messageName: 'showQuestion', payload: '{}'}, '*');
// Receive Result (receive response)
window.addEventListener("message", function (msg) {
// Message name and JSONified payload
const { message, payload } = msg.data;
if (message === 'answerResult') {
// do something with payload.isCorrect (true or false or null)
}
}
// Triggering the Show Question overlay (assuming LOLSDK is setup, see docs)
LOLSDK.Instance.ShowQuestion();
// Receiving
// Register an event delegate
LOLSDK.Instance.AnswerResultReceived += new AnswerResultReceivedHandler (this.HandleAnswerResult);
// Do something with the result
private void HandleAnswerResult(string json) {
JSONNode answerResult = JSON.Parse(json);
var isCorrect = answerResult["isCorrect"];
switch (isCorrect) {
case "true":
answerResultText.text = "correct";
break;
case "false":
answerResultText.text = "incorrect";
break;
default:
answerResultText.text = "no answer";
break;
}
}
Last modified 2yr ago