Forum Discussion

isabelle02's avatar
isabelle02
Community Member
2 months ago
Solved

Partial points Quizz storyline

Hello, 

I am trying to build a quiz in storyline but partials points aren't supported.

My logic for assigning points is: 

  •  If a wrong answer is selected, points for that question = 0 
  • Incomplete answer: partials points according to the weight of that question

I did a custom JavaScript to allow this. I had to create custom variables to do so. 

However, after my code calculate the total score, I can't set the storyline Quiz.Score to my custom variables. I set some triggers on the slider master but it doesn't update to my custom variable. 

It is important for me to have the Storyline Quiz.score updated so that later in my LMS I can automatically have the learner's grade

Any suggestions?

Here my triggers in the slide master

 

 

Here my JS code: 

Custom variable created in storyline are "totalScore" and "totalScorePercent"


var player = GetPlayer();
// =============== CONFIGURATION ===============
var checkboxVars = ["q12_checkbox1", "q12_checkbox2", "q12_checkbox3"]; 
var correctAnswers = ["q12_checkbox1", "q12_checkbox2"];
var wrongAnswerVar = "q12_wrong"; // Boolean variable to track wrong answer
var questionWeight = 2;
var totalScoreVar = "totalScore";
var percentScoreVar = "totalScorePercent";
var maxScore = 34;
// =============================================

// STEP 1: Check if wrong answer flag is set
var wrongAnswerFlag = player.GetVar(wrongAnswerVar);

// STEP 2: Calculate score
var Q_score = 0;

if (wrongAnswerFlag) {
  // Wrong answer detected -> points = 0
  Q_score = 0;
} else {
  // No wrong answer -> apply partial points logic
  // Read checkbox selections
  var selected = {};
  checkboxVars.forEach(function(cb) {
    selected[cb] = player.GetVar(cb);
  });
  
  // Count correct answers selected
  var correctSelected = correctAnswers.filter(function(cb) {
    return selected[cb];
  }).length;
  
  var totalCorrect = correctAnswers.length;
  
  if (correctSelected === totalCorrect) {
    // All correct answers -> full points
    Q_score = questionWeight;
  } else if (correctSelected > 0) {
    // Partial points: (correct selected / total correct) * question weight
    Q_score = (correctSelected / totalCorrect) * questionWeight;
    // Round to 2 decimal places to handle 0.33, 0.66 etc.
    Q_score = Math.round(Q_score * 100) / 100;
  } else {
    // No correct answers selected
    Q_score = 0;
  }
}

// STEP 3: Update total score
var totalScore = player.GetVar(totalScoreVar) || 0;
totalScore += Q_score;
player.SetVar(totalScoreVar, totalScore);

// STEP 4: Update total percent
var percent = (totalScore / maxScore) * 100;
if (percent > 100) percent = 100;
player.SetVar(percentScoreVar, Math.round(percent));
  • Nedim's avatar
    Nedim
    2 months ago

    In my second example, I used Storyline's built-in score variable, but not with the intention of modifying it directly. Even if it were possible to hard-code changes to it, doing so would likely cause unintended side effects in the overall scoring. I don't recommend altering it manually.

    My goal was to demonstrate an alternative approach for assigning partial points to your interaction allowing you to take full advantage of the built-in score variable. Storyline automatically calculates the total score based on the points assigned to each choice in the interaction, and this ensures proper score reporting to your LMS.

    Custom variables cannot be reported to an LMS unless they're passed through a built-in numeric graded question. You can assign the value of your custom variable to a numeric question variable, which can then be reported to the LMS, reflecting the value of your custom logic.

    Check this post for reference. It even includes a JavaScript solution for setting the overall score sent to the LMS directly, based on your custom total points. Story files are also available for download. Let me know if you need further help, but please make sure to clearly explain your specific scenario and the current logic you're using in your slides.

4 Replies

  • Nedim's avatar
    Nedim
    Community Member

    Your code looks fine and doesn’t contain any syntax errors. So, what exactly is the issue?

    Just a reminder: you cannot directly modify or alter Storyline’s built-in variables, such as ScorePercent and ScorePoints. However, you can create custom variables and set them equal to these built-in values at any point during the course.

    If your goal is to track scoring, you should consider building your interaction using Pick One Freeform Question type. These allow you to assign grading and take full advantage of Storyline’s built-in scoring system.

    What’s useful about this question type is that it supports partial scoring based on the weight assigned to each choice, making it easier to track learner performance accurately.

    Just a few days ago, I attended a great webinar by DavidAnderson​  on a topic that may not exactly match your scenario, but it can certainly shed some light on how to use Pick One Freeform question to assign partial points based on the weight assigned to each question choice. [Link to webinar]. 

    There are a few more graded question types in Storyline that allow 
    grading by choice, such as Multiple Choice and Freeform Hotspot questions. However, this option is limited to only one correct answer. That said, I believe you can adjust or find a workaround to better suit your specific requirements.

    A great post by JudyNollet​  is also worth exploring on this topic. It includes a sample Storyline file and a demonstration to help illustrate this technique. [Link to post]

    Another useful reference is an interaction I recently published for the E-Learning Challenge #518, where partial points are assigned to each answer based on the weight of the question. In that version, I used custom variables to calculate the score, but I also built an alternate version that leverages Storyline’s built-in score variables.

    If it’s not too much trouble, feel free to share more details about your scenario — or even upload your project file. I’d be happy to help set everything up according to your specific needs.

    • isabelle02's avatar
      isabelle02
      Community Member

      Hello Nedim, Thanks for the answer. 

      I would like to know, in your example  Elearning Challenge #518 , when you say that you use Storyline's built-in score, are you able to modify its value?
      Like this when your project is publish on a LMS, it can see your result for the quiz? 

      Also, do you know if it's possible to publish a custom variables with the scorm package when exporting ? Like this, my LMS will be able to see my custom variables.

      Thanks for your help!

      • Nedim's avatar
        Nedim
        Community Member

        In my second example, I used Storyline's built-in score variable, but not with the intention of modifying it directly. Even if it were possible to hard-code changes to it, doing so would likely cause unintended side effects in the overall scoring. I don't recommend altering it manually.

        My goal was to demonstrate an alternative approach for assigning partial points to your interaction allowing you to take full advantage of the built-in score variable. Storyline automatically calculates the total score based on the points assigned to each choice in the interaction, and this ensures proper score reporting to your LMS.

        Custom variables cannot be reported to an LMS unless they're passed through a built-in numeric graded question. You can assign the value of your custom variable to a numeric question variable, which can then be reported to the LMS, reflecting the value of your custom logic.

        Check this post for reference. It even includes a JavaScript solution for setting the overall score sent to the LMS directly, based on your custom total points. Story files are also available for download. Let me know if you need further help, but please make sure to clearly explain your specific scenario and the current logic you're using in your slides.

  • isabelle02's avatar
    isabelle02
    Community Member

    Thanks a lot for your help!
    I solve the issue with this javascript on my last slide and it works on my LMS.

    var player = GetPlayer();
    var score = player.GetVar("totalScorePercent");
    var passingScore = 80;
    SetScore(score, 100, 0);
    if (score >= passingScore) {
        SetPassed();
    } else {
        SetFailed();
    }
    SetStatus("completed");