Hi,
I'm using MultiAnswer.pl and I want to change the error message a student gets if they enter a string instead of a number from "In answer 1: Variable 't' is not defined in this context" to something like "Your answer must be a number." I've tried the suggestions in the documentation for MultiAnswer.pl, I've been able to change the error message in other situations, but not for this case (String answer when a number is expected.). The problem I'm writing asks the student to enter dimensions for two matrices which will *not* produce a product. The code is at the end of this note.
Thanks--rac
---------Code-------------------------------------
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"parserMultiAnswer.pl",
"answerHints.pl",
);
TEXT(beginproblem());
$showPartialCorrectAnswers = 1;
$multians2 = MultiAnswer(2,2,3,2)->with( #Correct answer not really used
singleResult => 1,
checkTypes => 0,
checker => sub {
my ( $correct, $student, $self ) = @_;
my ( $sm1,$sn1,$sm2,$sn2 ) = @{$student};
if ( is_a_number($sm1) && is_a_number($sn1)
&& is_a_number($sm2) && is_a_number($sn2) ) {
if ( $sn1!=$sm2 ) { return 1; } else {return 0;}
} else {
$self->{ans_message}='Your answers must be numbers.';
Value::Error("Enter numbers for your answers.");
$self->setMessage(2,"Enter a number.") if (~(is_a_number($sn1))); ###NOTE: I tried various permutations like the three lines above.###
### I had one for each answer like the last one--left one for reference.
return 0;
}
}
);
BEGIN_TEXT
State the dimensions for a pair of matrices, \(C\) and \(D\), which cannot be multipled together. In other words, \(CD\) cannot be calculated.
$BR $BR
\(C\): \{$multians2->ans_rule(5)\} rows, \{$multians2->ans_rule(5)\} columns,
\(D\): \{$multians2->ans_rule(5)\} rows, \{$multians2->ans_rule(5)\} columns
END_TEXT
ANS( $multians2->cmp);#->withPostFilter(AnswerHints(
#sub {
# my ($correct,$student,$ans) = @_;
# return $ans->{ans_message} =~ /not defined/;
#} =>["Note: Your answers must be numbers.", Score => 0, replaceMessage => 1])));
##Using AnswerHints produced an error: Can't call method "withPostFilter" without a package or object reference at line 143 of (eval 2480)
##The line number is off since this was part of a longer problem.
ENDDOCUMENT(); # This should be the last executable line in the problem.