## WeBWorK Problems

### Error messages shown on "Preview", not just "Submit"

by Peter Selinger -
Number of replies: 2
I wrote a problem with a custom answer checker. The student is supposed to reduce a given matrix to echelon form.

To be extra helpful, my answer checker generates informative error messages with Value->Error. For example, if the answer is not in echelon form, it generates the message "Not in echelon form", and if the matrix is not equivalent to the given matrix, it generates the message "Not row equivalent". The idea was to give the student some additional feedback on top of the usual "correct" and "incorrect", so that they can see more easily why their answer was wrong.

I just discovered that when the student presses "Preview my answer", those informational messages are also shown. Although the system does not show whether the previewed answer is correct, it nevertheless shows messages like "not in echelon form" and "not row equivalent". So by just previewing the answer, the students can see if their answer is correct or not. So instead of having 5 attempts per question as I intended, they effectively have an infinite number of attempts.

This is not what I want. I would like the messages to be shown when checking or submitting the answer, but not when previewing it. I don't understand why the answer checker is called *at all* when the student is only previewing what they entered. How can I fix this?

Note: I did have to set the showEqualErrors => 1 option for the answer checker. If I don't set this flag, the user doesn't get my informational messages at all (not even during normal answer checking).

Is there another flag I can set, or something I can call besides Value->Error, to ensure they get the message *only* in the context of answer checking, and *not* in the context of previewing?

Thanks. I am attaching a sample problem, as well as some macro files that the problem uses. WebWorK version is 2.12.
In reply to Peter Selinger

### Re: Error messages shown on "Preview", not just "Submit"

by Michael Gage -
If you load PGinfo.pl into any pg problem and then place

listVariables();

anywhere in the "code" part of the pg problem you will get a list of
all of the variables being made available to the PG problem within the
safe compartment. This is quite useful in situations like yours.

If you click the preview answers button you will see that a variable
called
$inputs_ref->{previewAnswers} has been defined. This is only defined when the preview answer button has been pressed. Have your answer checker check for that variable before it runs. It might be necessary to use$main::inputs_ref since I'm not sure whether your answer checker is being executed within the "main::" namespace.

There is not much documentation but PGinfo.pl is not too hard to read.
There are a few other subroutines defined there.

This is also useful for grabbing environment information:

In reply to Michael Gage

### Re: Error messages shown on "Preview", not just "Submit"

by Peter Selinger -

Hi Michael,

amazing! That is exactly the information I needed, to solve this problem and hopefully some future ones. Thanks!

In my opinion, the direct use of Value->Error in answer checkers should be deprecated and replaced by two more specific functions: one to report type errors (which should be shown during previewing), and the other to give feedback on incorrect answers (which should not be shown during previewing). I have now implemented these in a private library and will use them in my problems:

# Report an ill-formed answer. This is used in answer checkers for messages that should
# be shown when previewing, checking, or submitting the answer.
sub IllFormed ($) { my ($msg) = @_;
Value->Error($msg); } # Provide feedback about an incorrect answer. This is used in answer checkers for messages # that should be shown when checking or submitting the answer, but not when previewing it. sub Feedback ($) {
my ($msg) = @_; unless (defined$inputs_ref->{previewAnswers}) {
Value->Error(\$msg);
}
}


Maybe something like this could be eventually added to the standard PG library. Thanks again for the valuable pointers!

-- Peter