Forum Discussion

JimOwen-f418d1f's avatar
JimOwen-f418d1f
Community Member
2 years ago

Concatenate slide numbers into variable

Hello,

I would like to keep track of a user's progress through a course by concatenating slide numbers (and a comma) every time a slide is started. I can get the Project.SlideNumber variable, but it is a number and I can't add it to a string variable, not to mention I can't figure out how to concatenate it even if it were a string. Any ideas on how to accomplish this?

  • SBP_Inc's avatar
    SBP_Inc
    Community Member

    let learnersPath = ''; // define learnersPath as a string type SL variable

    // Code for a javascript trigger to run at slide timeline start
    const slideNumberFromPlayer= 1; // example; get actually from the Player() using your JS code
    learnersPath = learnersPath + "," + exampleSlideNumber;

    // console.log(learnersPath);

     

  • Thank you! I figured out that I need to resort to JS to do this. It's all working. I am going to send an email with the concatenated slide numbers and some other things, but \n does not work for a line break, nor does  \u000A . How is this accomplished?

  • For anyone who needs this, I have learned how to add line breaks to the body of JS output when composing an email. The string '%0D%0A' acts as a line break. So my code looks something like this:

    var p = GetPlayer()
    var progress = p.GetVar("progress")
    var reviewed = p.GetVar("reviewed")
    var answers = p.GetVar("answers")
    var times = p.GetVar("times")
    var feedback = p.GetVar("TextEntry")
    var br = '%0D%0A'

    var body = feedback + br + br
    var body = body + "PROGRESS " + progress + br
    var body = body + "REVIEWED " + reviewed + br
    var body = body + "ANSWERS " + answers + br
    var body = body + "TIMES " + times + br

    var email="me@email.com";
    var subject="Sent from Storyline";
    var mailto_link='mailto:'+email+'?subject='+subject+'&body='+body;
    win=window.open(mailto_link,'emailWin');