Forum Discussion
SwiftC
10 days agoCommunity Member
Issue with Execute JavaScript Trigger in Storyline 360
I am working on a project in Articulate Storyline 360 and I'm trying to execute a JavaScript function when the timeline starts on a slide. The function is supposed to replace the default values of project text variables with specific messages based on the slide number.
Here is the JavaScript code I'm using:
function setTexts(slideNumber) {
console.log("setTexts function called with slideNumber: " + slideNumber); // Log the function call
var correctTexts = [
"This is a credit card statement with the amount of money that student owes.",
"This document is intended to give a record of purchases and payments. It gives the card holder a summary of how much the card has been used during the billing period, as well as the amount that is due for that billing cycle."
];
var incorrectPromptTexts = [
"Here's a hint, there are dollar amounts on there and itemized activity, what type of document best fit these?",
"Think about why you would need a statement for bills, please try again."
];
var studentUnderstandTexts = [
"Got it! I always get these confused with my car insurance for some reason.",
"Yes now that I think about it, having an itemized record is very helpful, even if it's quite annoying to always get these in the mail."
];
var positiveFeedbackTexts = [
"_user_ you answered correctly! Awesome job!",
"_user_ you got the question correct!",
"_user_ you answered correctly awesome job!",
"_user_! You answered correctly!",
"_user_! You answered the question right!",
"_user_, You answered right!",
"_user_, You answered the question right!",
"_user_, you answered correctly! Keep it up!",
"_user_, You answered the question right! Keep up the great work",
"_user_ you are doing great! Keep it up!"
];
var negativeFeedbackTexts = [
"_user_, sorry. the answer you gave wasn't what I was looking for.",
"_user_, your answer was not quite right.",
"_user_, It looks like you picked the wrong answer.",
"_user_, I'm afraid the answer you chose wasn't the best one."
];
var player = GetPlayer();
// Log the text being set for each variable
var correctText = correctTexts[slideNumber - 1];
console.log("Setting Correct to: " + correctText);
player.SetVar("Correct", correctText);
var incorrectPromptText = incorrectPromptTexts[slideNumber - 1];
console.log("Setting IncorrectPrompt to: " + incorrectPromptText);
player.SetVar("IncorrectPrompt", incorrectPromptText);
var studentUnderstandText = studentUnderstandTexts[slideNumber - 1];
console.log("Setting StudentUnderstand to: " + studentUnderstandText);
player.SetVar("StudentUnderstand", studentUnderstandText);
// Randomly select positive and negative feedback
var randomPositiveFeedback = positiveFeedbackTexts[Math.floor(Math.random() * positiveFeedbackTexts.length)];
var randomNegativeFeedback = negativeFeedbackTexts[Math.floor(Math.random() * negativeFeedbackTexts.length)];
console.log("Setting PositiveFeedbacktoUser to: " + randomPositiveFeedback);
player.SetVar("PositiveFeedbacktoUser", randomPositiveFeedback);
console.log("Setting NegativeFeedbacktoUser to: " + randomNegativeFeedback);
player.SetVar("NegativeFeedbacktoUser", randomNegativeFeedback);
}
// Call the function with the current slide number
setTexts(GetPlayer().GetCurrentSlide().GetSlideNumber());
When I preview the project, the console provides the following message:
bootstrapper.min.js:2 actionator::exeJavaScript - Script1 is not defined
I have defined the setTexts function and ensured that it is called correctly in the "Execute JavaScript" trigger, but the error persists.
Steps I've Taken:
- Defined the setTexts function.
- Added the function call setTexts(GetPlayer().GetCurrentSlide().GetSlideNumber()); in the "Execute JavaScript" trigger.
- Verified that the function is being called correctly.
Any help or suggestions on how to resolve this issue would be greatly appreciated. Thank you!
No RepliesBe the first to reply