Am setting a automated subtitle function in storyline, currently I have the next subtitle automatically generated by hitting the next button when the user has finished reading there current subtitle how ever I want to set it up so this next button script is automatically run after a second.
To do this I want to use the setInterval Function that is in javascript but it does not seem to be working does any one know if this is possible in stoyline?
var player = GetPlayer(); var speakerText = player.GetVar("SpeakerText"); var postionInScript = player.GetVar("TextPostion"); var currentSlideNumber = player.GetVar("SlideNumber"); var newSlide = player.GetVar("NewSlide"); var subtitle = ""; var wordCount = 0; var maxWordCount = 10; var PunctuationCheck = ["."] var space = " " var beginningOfSlide = "SLIDE" var Len = speakerText.length;
var subtitle = function() { if(newSlide) { var searchWord = beginningOfSlide + currentSlideNumber;
This is the the code currently, am unsure where it is going wrong It will have something to do with the subtitle being a function as it was not the last time it ran or the actual setInterval, (BTW I know the code is not great only started javascript 2 weeks ago)
To help me get a handle on your code I ran it through a JS Beautifier . It seems you might be missing a closing a bracket on your subtitle function.
What browser are you using for development? You might try hitting F12 while viewing the course to open the Console. There you will details about errors.
Was going to suggest the same. You might also try running your function without the setInterval. If it doesn't work, the problem isn't with the setInterval call. Unfortunately (fortunately... maybe) js tends to fail silently. So if there's a problem anywhere in the function it'll just fail to run. The console usually reveals where the problem is.
5 Replies
Hi Jacob,
setInterval should work. Can you show an example that's not working?
var player = GetPlayer();
var speakerText = player.GetVar("SpeakerText");
var postionInScript = player.GetVar("TextPostion");
var currentSlideNumber = player.GetVar("SlideNumber");
var newSlide = player.GetVar("NewSlide");
var subtitle = "";
var wordCount = 0;
var maxWordCount = 10;
var PunctuationCheck = ["."]
var space = " "
var beginningOfSlide = "SLIDE"
var Len = speakerText.length;
var subtitle = function()
{
if(newSlide)
{
var searchWord = beginningOfSlide + currentSlideNumber;
for(var i = 0; i
{
if(speakerText[i] == searchWord[0])
{
for(var j = 0; j
{
if(speakerText[i + j] == searchWord[j])
{
if(j == searchWord.length - 1)
{
postionInScript = i + j + 2;
newSlide = false;
player.SetVar("NewSlide", newSlide);
break;
}
}
else
{
break;
}
}
}
}
newSlide = false;
player.SetVar("NewSlide", newSlide);
}
if(postionInScript
{
var Escape = false;
for(var i = postionInScript; i
{
var endOfBlock = false
for(var j = 0; j
{
if(speakerText[i] == PunctuationCheck[j])
{
subtitle += speakerText[i];
endOfBlock = true;
}
}
if (speakerText[i] == beginningOfSlide[0])
{
for (var j = 0; j
{
if (speakerText[i + j] == beginningOfSlide[j])
{
if (j == beginningOfSlide.length - 1)
{
Escape = true;
endOfBlock = true;
}
}
}
}
if(!endOfBlock && speakerText[i] == space)
{
subtitle += speakerText[i];
wordCount++;
if(wordCount > maxWordCount)
{
subtitle += "...";
endOfBlock = true;
}
}
else if( !endOfBlock )
{
subtitle += speakerText[i];
}
if (endOfBlock && Escape)
{
break;
}
else if(endOfBlock)
{
postionInScript = i+1;
player.SetVar("Subtitle", subtitle);
player.SetVar("TextPostion", postionInScript);
break;
}
}
}
}
setInterval(function(){subtitle()},1000);
This is the the code currently, am unsure where it is going wrong It will have something to do with the subtitle being a function as it was not the last time it ran or the actual setInterval, (BTW I know the code is not great only started javascript 2 weeks ago)
Hi Jacob,
To help me get a handle on your code I ran it through a JS Beautifier . It seems you might be missing a closing a bracket on your subtitle function.
What browser are you using for development? You might try hitting F12 while viewing the course to open the Console. There you will details about errors.
jK
Are you sure?
I have just run though it and it seems fine to me for the missing brackets
Was going to suggest the same. You might also try running your function without the setInterval. If it doesn't work, the problem isn't with the setInterval call. Unfortunately (fortunately... maybe) js tends to fail silently. So if there's a problem anywhere in the function it'll just fail to run. The console usually reveals where the problem is.
This discussion is closed. You can start a new discussion or contact Articulate Support.