Articulate 360 Storyline JS触发报错:Script1未定义问题求助
解决Articulate Storyline中JavaScript触发器报错“Script1 is not defined”的问题
问题描述
在Articulate 360 Storyline中创建幻灯片触发器,设置为时间轴启动时执行JavaScript,代码旨在根据幻灯片编号替换项目文本变量的默认值,但预览时控制台报错:
bootstrapper.min.js:2 actionator::exeJavaScript - Script1 is not defined
原代码如下:
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); }
报错原因
- 函数未调用:仅定义了
setTexts函数但未执行调用,Storyline执行触发器JS时会直接运行代码内容,无顶层可执行代码时会抛出类似找不到脚本的错误。 - 参数大小写不一致:函数参数定义为
SlideNumber(首字母大写),但内部使用slideNumber(小写),会导致变量未定义的隐性问题。
解决方案
修正参数大小写,并在函数定义后添加调用语句,传入当前幻灯片编号。以下是修正后的完整代码(已翻译为中文):
function setTexts(slideNumber) { console.log("setTexts函数已调用,幻灯片编号: " + slideNumber); var correctTexts = [ "这是一份信用卡账单,显示学生所欠金额。", "这份文档用于记录消费和付款情况,会向持卡人汇总账单周期内的卡使用情况以及该周期的应付款项。" ]; var incorrectPromptTexts = [ "提示一下,这份文档里有金额和明细交易记录,哪种文档最符合这些特征?", "想想为什么账单需要对账单,请再试一次。" ]; var studentUnderstandTexts = [ "明白了!我之前总是把它和汽车保险单搞混。", "对哦,现在想想,有明细记录确实很有用,虽然总是收到这些邮件有点烦。" ]; var positiveFeedbackTexts = [ "_user_ 回答正确!太棒了!", "_user_ 答对了!", "_user_ 回答正确,做得好!", "_user_!你答对了!", "_user_!回答正确!", "_user_,答对了!", "_user_,回答正确!", "_user_,回答正确!继续加油!", "_user_,回答正确!保持出色表现!", "_user_ 你做得很棒!继续加油!" ]; var negativeFeedbackTexts = [ "_user_,抱歉,你的答案不是我要找的。", "_user_,你的答案不太对。", "_user_,看起来你选错了答案。", "_user_,恐怕你选的不是最佳答案。" ]; var player = GetPlayer(); // 为各变量赋值并打印日志 var correctText = correctTexts[slideNumber - 1]; console.log("设置Correct变量为: " + correctText); player.SetVar("Correct", correctText); var incorrectPromptText = incorrectPromptTexts[slideNumber - 1]; console.log("设置IncorrectPrompt变量为: " + incorrectPromptText); player.SetVar("IncorrectPrompt", incorrectPromptText); var studentUnderstandText = studentUnderstandTexts[slideNumber - 1]; console.log("设置StudentUnderstand变量为: " + studentUnderstandText); player.SetVar("StudentUnderstand", studentUnderstandText); // 随机选择正负反馈文本 var randomPositiveFeedback = positiveFeedbackTexts[Math.floor(Math.random() * positiveFeedbackTexts.length)]; var randomNegativeFeedback = negativeFeedbackTexts[Math.floor(Math.random() * negativeFeedbackTexts.length)]; console.log("设置PositiveFeedbacktoUser变量为: " + randomPositiveFeedback); player.SetVar("PositiveFeedbacktoUser", randomPositiveFeedback); console.log("设置NegativeFeedbacktoUser变量为: " + randomNegativeFeedback); player.SetVar("NegativeFeedbacktoUser", randomNegativeFeedback); } // 调用函数,传入当前幻灯片编号 var currentSlideNumber = GetPlayer().GetVar("SlideNumber"); setTexts(currentSlideNumber);
额外注意事项
- 确保已在Storyline中创建所有用到的文本变量:
Correct、IncorrectPrompt、StudentUnderstand、PositiveFeedbacktoUser、NegativeFeedbacktoUser。 - 若需指定特定幻灯片编号,可直接传入固定数值,例如
setTexts(1)。
内容的提问来源于stack exchange,提问作者Sentient Onion
相关产品推荐
相关产品推荐

