Moodle Plugins directory: VPL Question | Moodle.org
VPL Question
VPL Question type
Version: 2.0.0 (April 2024)
Authors:
- Astor Bizard
- Florent Paccalet (legacy version).
This software is part of the Caseine project.
This software was developped with the support of the following organizations:
- Université Grenoble Alpes
- Institut Polytechnique de Grenoble
Introduction
VPL Questions are questions that can fit within a Moodle quiz. They are intended to create small to medium coding exercises, based on the Virtual Programming Lab plugin.
They are designed to offer a simple interface for students, while keeping the power and versatility of Virtual Programming Labs.
VPL Questions Architecture
A picture is worth a thousand words, so here is how it works (you can also read the thousand words right below the picture!):
A VPL Question is (as its name says) based on a VPL (Virtual Programming Lab).
The execution and evaluation of the question takes place inside that VPL, which allows powerful customizations.
A single VPL can be used for several questions, as long as it is located in the same course.
In order to execute and evaluate student's code in the VPL, the question sends that code (injected within the required file, at the place of the {{ANSWER}} tag) in a new VPL submission. The submission also includes question-specific execution files. The VPL then replaces its own execution files by the ones present in the submission.
This is what allows several questions to be based on the same VPL: as the execution files are question-specific, different execution behaviors (e.g. different test cases) can be achieved on the same VPL. However, this can not be achieved for standard execution scripts.
Create a VPL Question
Step 1: Create a dedicated VPL
The first step to create a VPL Question is to create the VPL it will be using.
To do so, simply create a new VPL inside your course.
It is (strongly) recommended to create it inside a hidden section of the course, and make it available. The goal is to hide it from students, while still allowing them to make submissions to it.
When the VPL is created, there are a few settings you will have to change before it can be used:
- Edit settings > Submission period: It is recommended to disable the deadline (Due date).
- Edit settings > Submission restrictions: Set the Maximum number of files to a large enough number, as submissions will include execution files.
- Edit settings > Common module settings: If you put the VPL inside a hidden section, make sure the Availability is set to Available but not shown on course page.
- Execution options: Set Run and Evaluate to Yes.
- Execution files: Create a file named pre_vpl_run.sh, and paste the following code in it (this is the code that deals with submitted execution files):
for qvplfile in `ls -1`
do
file=${qvplfile%_qvpl}
if [ -x $file ]; then executable=true; else executable=false; fi
test "$qvplfile" != "$file" && mv "$qvplfile" "$file"
if $executable; then chmod u+x $file; fi
done
- Required files: Create one (and only one) required file. You can write some basic code in it (like class declaration in java, an empty main function, ...).
You can also edit/add execution files. Please note that:
- Standard execution scripts will not be editable per-question. Please edit them from the VPL.
- Other execution files will be editable per-question. However, please create them first in the VPL (you won't be able to create them from a question).
IMPORTANT: Students submissions on this VPL will be discarded by the VPL Question (this behavior can be changed by an administrator in this plugin settings). This is why it is important to create a dedicated VPL (and not to use a VPL where students may want to retrieve their previous submissions).
Step 2: Create one or more VPL Questions
Once a dedicated is created by following the instructions above, you are now ready to create your VPL Questions !
To do so, create a question either from a Quiz or a Question bank, and select VPL Question:
Let's breakdown what you can do in the question editing form:
- General: You fill find here all standard settings for a question, like question name and description.
- VPL Question template: Here you can select the VPL you created earlier. This will allow you to edit the required file. Please make sure that it includes the {{ANSWER}} tag: this is where the student's code will be injected. Also, please note:
- Answer template: Here you can edit what will be pre-filled in the student's answer box. It can be left empty.
- Teacher correction: Please write here your correction for the question. This is what will be used as the "Correct answer" for Quiz feedback.
If Validate is checked, the provided answer will be checked against test cases upon question save. This is very useful to check everything is working fine on VPL side, and that both your correction and your tests are correct. - Execution files and evaluate settings: This is where you can edit the execution and evaluation behavior of the question. Once again, all modifications done here will only affect the current question.
- You can edit execution files (most commonly vpl_evaluate.cases). If there is an execution file that you created in the VPL but you do not need in this question, write UNUSED at the beginning of the file: it will be ignored.
Note: Execution files are only sent to the VPL upon question evaluation. If you need them during execution (Run), please set them as Files to keep when running in the VPL. - You can also change the behavior of the Pre-check button (make it act as the Debug button on the VPL, use the execution files above, or use other files). In the last case, you will be able to edit another set of execution files, this time specific to the Pre-check button.
- You can finally decide whether students need to achieve perfect VPL grade to get the question correct, or use relative VPL grade to get a proportional note on the question.
- You can edit execution files (most commonly vpl_evaluate.cases). If there is an execution file that you created in the VPL but you do not need in this question, write UNUSED at the beginning of the file: it will be ignored.
Known issues
- Test cases hacking
Test cases, along with other execution files specific to a question, are sent to the VPL as submission files. Even if the VPL is hidden, it has to be available to students so that they can submit to it. This leads to a possibility for students to find access to the VPL, thus to the execution files they submitted. Please be aware of that possibility - what you decide to do about it is up to you.



It seems that VPL, by default, runs R programs within a graphical interface.
This is not supported by VPL questions.
You would need to rewrite the vpl_run.sh script to run the program as command line.
Sorry for the inconvenience.
Best regards,
Astor
I just started creating VPL questions and have a question myself.
To avoid creating several dedicated VPLs - one for each question - could I simply create a single dedicated VPL for my questions and use it for all my VPL questions (since they are somewhat basic)? Since the execution files and evaluation settings are set up directly in the VPL question, I do not see why this would not be possible. I noticed that when configuring the VPL question, the evaluation files in the VPL are modified, so this might lead to uncontrolled behaviour.
Anyway, I made a small test with two distinct questions based on the same VPL, on the same questionnaire, with distinct evaluation behaviours, and everything seemed to work fine.
Is this the correct (or at least an acceptable) way of setting up VPL questions? If so, wouldn't it be better to simply set up a "empty" VPL instance which is initialized along with the VPL question?
Thank you very much for the wonderful plugin.
I am glad you find the plugin useful!
This is indeed a correct way to use VPL Questions! This is even the intended way to set them up
The reason we are not using a virtual, empty VPL activity is that we often want to setup generic, sometimes advanced, evaluation mechanism. In that case, we put it in the base VPL activity, and it can be easily re-used across multiple questions.
Best regards,
Astor
Hi,
First of all, thank you for this great plugin – it's exactly what we were looking for.
About us:
We're an educational organization that teaches programming to thousands of high school students. We're currently migrating our assessment system to VPL and have decided to use the VPL Question plugin as our main solution.
The challenge:
Our students have little to no background in computers or programming. Because of this, we're looking for ways to present feedback in a more visual and beginner-friendly way.
Currently, the evaluation output window (vpl_eval_details_q208) only supports plain text. This limits us in two ways:
Formatting limitations: We can't use visual elements to make feedback clearer and more accessible for young learners.
RTL/LTR mixing issues: Our feedback combines Right-to-Left text (Hebrew) with English code and terms. In plain text, this mix breaks the display and creates confusing, garbled output. With HTML5, we could use proper dir attributes to handle bidirectional text correctly.
Feature request:
Would it be possible to add HTML5 support to this output window (or introduce an alternative output area that supports HTML)?
This would allow us to:
Use colors and formatting to highlight errors vs. successes
Properly handle bidirectional (RTL/LTR) text
Add visual elements to make feedback clearer
Create a more encouraging experience for beginners
We'd be happy to provide more details about our use case or help test if needed.
Thanks for considering this!
I recently got aware of a possible issue with the conditions under which a VPL-Question answer is saved during a running Moodle quiz.
Our testing specs:
- Moodle: 5.1.1+ - Build 20251212
- VPL: 4.4.1 - 2025112512
- VPL-Jail Server: 4.0.3
- VPL Question: 3.3.0 for Moodle 4.2+ - 2025121601
When a Moodle quiz is running and the student sees a VPL-Question, his code seems to solely be saved when (1) he executes / pre-checks the code (button interaction) or (2) if he navigates to the next or previous question (also a button interaction). Nevertheless, when editing the answer in a VPL Question, after 30 seconds or so a message appears on the right side that pretends that the answer is being saved, together with a timestamp. Actually, this seems to have no effect - the answer is not really saved. If the quiz has a time limit and the limit runs out, the student is automatically redirected to the results page where he can have a look at the answers he gave in the quiz and he will find that his latest inputs in the recent VPL-Question that was open before the automatic closing of the quiz are not present. He sees only the version of his answer that was stored when he executed his code. Without any execution / pre-check, he will find his answer completely empty.
The behaviour of the standard free-text questions is different: Even the latest input, e.g. just one second before an automatic closing of a time-limited quiz, is reliably stored and thus visible to the student in the result page. I assume that the finish / redirect event somehow triggers a submit for the answer. For real examination scenarios, this would be the preferred behavior also for VPL-Questions. Otherwise, a student could lose parts of his answers that he did'nt have the time to execute or pre-check shortly before the quiz runs out.
I assume that this is related to the VPL Question plugin, or am I missing something? Can we control this behaviour by configuration?
Thanks in advance.
Best regards
Kay
Thank you for your feedback!
You are right, the current evaluation output display is limited. I think it is the legacy of first versions that I never bothered to change.
I will see what I can do in the next release I am working on!
Best regards,
Astor
Thanks for the report. It makes sense given the way answers are saved by VPL Questions.
I did not anticipate that kind of usage with limited time Quizzes.
I will try and fix this issue as soon as possible!
Best regards,
Astor
Here is my implementation of the use_async_evaluation function
/**
* Determine if this question should use asynchronous evaluation or not.
* @return boolean
*/
public function use_async_evaluation() {
// Check that the question uses async evaluation, that it is allowed from admin settigns and that a step is set.
// If in regrade (dry or normal) force synchronous evaluation.
$isregrading = optional_param('regrade', 0, PARAM_BOOL)
|| optional_param('dryrunregrade', 0, PARAM_BOOL)
|| optional_param('regradeselectedattempts', 0, PARAM_BOOL)
|| optional_param('regradeselectedquestions', 0, PARAM_BOOL)
|| optional_param('regradealldrydo', 0, PARAM_BOOL);
return !empty($this->useasynceval) && $this->step !== null && get_config('qtype_vplquestion', 'allowasynceval')
&& !$isregrading
&& !optional_param('previewid', 0, PARAM_INT);
}
Thank you so much for implementing HTML support! We really appreciate you taking the time to address our request.
We've started testing and it's a great step forward. However, the current allowedTags and allowedAttrs lists are too restrictive for our use case.
We've built a visual feedback template that includes:
Progress gauge using svg and path
Results table using table, tbody, tr, td
Collapsible sections using onclick and id attributes
RTL support using dir attribute
Visual styling using style attribute
All of these are currently blocked by the sanitizer, which breaks our feedback layout.
Would it be possible to either:
Expand the allowed lists to include these elements, or
Add a bypass mechanism (e.g. a wrapper tag) that skips sanitization for trusted content from the evaluation script?
Since the HTML is generated server-side by our evaluation script (not user input), we believe it can be safely trusted.
Happy to test any solution or contribute code if needed.
Thanks again for your great work!
Jack
Thanks for the suggestion.
I am not sure to totally understand your point, as you seem to sometimes say that regrade should be done asynchronously, and sometimes say that it should be done synchronously.
The current idea is to do dry regrading synchronously, and to follow question setting on every other case (standard workflow or true regrade).
I will take into account your suggestion to better detect dry regrade (include 'regradealldrydo' and 'dryrunregrade' params).
I hope this will suit your needs.
Best regards,
Astor
Update 3.4.1 that was released includes more tags (esp. table tags and style).
It still does not allow "dir" attribute which is a mistake by me, and will be fixed in the next release.
For collapsible regions, "details" and "summary" tags will be allowed as well in the next release.
For any javascript (onclick or not) or wrapper tag to bypass sanitization, it is a big no-no. Because even if your use case may capture student output and control everything, this is not the case for every evaluation mechanism (and obviously student-generated javascript should never be trusted by default).
Best regards,
Astor
This is fantastic news! Thank you so much for the quick response and for adding these features. We really appreciate your work on this plugin - it's not something we take for granted.
The addition of table tags and style attribute in 3.4.1 is a big step forward for us. And the upcoming support for "dir" attribute and "details"/"summary" tags is exactly what we need for RTL and collapsible sections.
We completely understand your position on JavaScript/onclick - it makes total sense from a security perspective.
Two quick questions:
Do you have a rough timeline for the next release (with dir, details, and summary)?
Is there any chance SVG support (svg, path tags) could be included? We use it for a progress gauge to show students their score visually. If not, we'll find an alternative with CSS.
Thanks again for your dedication to this plugin and for being so responsive to the community!
Best regards,
Jack
The update 3.4.2 is now online and should address your concerns.
Best regards,
Astor
as I frequently export questions from a course template to other courses, I faced the same problem reported by @Kay Otto. Usually, what I did to solve this was to manually modify the vpltemplate field in the database.
Based on @Kay Otto's suggestion, I rewrote questiontype.php, overriding export_to_xml to export the vpltemplatename and modifying import_from_xml to use the vpltemplatename if the templatevpl was not in the same course.
Of course, before importing the VPL Questions, the VPL Template must be imported from the course template using "Course reuse".
You can find the fix here: https://gitlab.com/osangoi/moodle-qtype_vplquestion/-/commit/b76f71cb195a42947a945078885f87ac65e25d48
I implemented another fix for course reuse. If, during the import phase, the user performs a partial import that does not include the 'Include activities and resources' option, the process is unable to find the VPL template. With this fix, if the VPL template isn't found, the program attempts to find a VPL template in the current course with the same name as the original one.
You can find the fix here: https://gitlab.com/osangoi/moodle-qtype_vplquestion/-/commit/6004e5c56cf9953c7e9cb7df65d6af68da75f446