Skip to content

Commit

Permalink
student_id and initial_seed are exam-level variables
Browse files Browse the repository at this point in the history
The variables `student_id` and `initial_seed` are set in the exam scope
and available to all questions. They can be used to coordinate the
randomisation across questions.

The initial seed is either a value from the built-in random number
generator, or loaded from the SCORM element 'numbas.initial_seed'.
The LTI provider can use this to force attempts to use a particular
seed, so they match a printed copy, for example.

fixes #805
  • Loading branch information
christianp committed Dec 19, 2024
1 parent ec7581e commit 8ce6018
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 124 deletions.
18 changes: 16 additions & 2 deletions runtime/scripts/exam.js
Original file line number Diff line number Diff line change
Expand Up @@ -636,11 +636,15 @@ Exam.prototype = /** @lends Numbas.Exam.prototype */ {
init: function()
{
var exam = this;
if(exam.store) {
job(exam.store.init,exam.store,exam); //initialise storage
job(exam.set_exam_variables, exam);
}
job(exam.chooseQuestionSubset,exam); //choose questions to use
job(exam.makeQuestionList,exam); //create question objects
exam.signals.on('question list initialised', function() {
if(exam.store) {
job(exam.store.init,exam.store,exam); //initialise storage
job(exam.store.init_questions,exam.store,exam); //initialise question storage
job(exam.store.save,exam.store); //make sure data get saved to LMS
}
});
Expand Down Expand Up @@ -671,9 +675,10 @@ Exam.prototype = /** @lends Numbas.Exam.prototype */ {
}
this.loading = true;
var suspendData = this.store.load(this); //get saved info from storage
exam.seed = suspendData.randomSeed || exam.seed;
job(exam.set_exam_variables, exam);
job(function() {
var e = this;
e.seed = suspendData.randomSeed || e.seed;
var numQuestions = 0;
if(suspendData.questionGroupOrder) {
this.questionGroupOrder = suspendData.questionGroupOrder.slice();
Expand Down Expand Up @@ -714,6 +719,15 @@ Exam.prototype = /** @lends Numbas.Exam.prototype */ {
exam.signals.trigger('ready');
});
},

/** Set exam-level variables.
*
*/
set_exam_variables: function() {
this.scope.setVariable('initial_seed', Numbas.jme.wrapValue(this.seed));
this.scope.setVariable('student_id', Numbas.jme.wrapValue(this.student_id));
},

/** Decide which questions to use and in what order.
*
* @fires Numbas.Exam#chooseQuestionSubset
Expand Down
Loading

0 comments on commit 8ce6018

Please sign in to comment.