From 4c79dc93d5df3ce6f371c86dcb700fc36759cfa6 Mon Sep 17 00:00:00 2001 From: Alex Jordan Date: Wed, 20 May 2026 21:31:26 -0700 Subject: [PATCH 1/2] clarify in POD for answerHints.pl that checkCorrect and checkTypes only apply to CODE incorrect answers --- macros/answers/answerHints.pl | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/macros/answers/answerHints.pl b/macros/answers/answerHints.pl index e91327d5c5..6e625946fe 100644 --- a/macros/answers/answerHints.pl +++ b/macros/answers/answerHints.pl @@ -32,8 +32,10 @@ =head2 AnswerHints =item C 0 or 1 >>> -1 means check for messages even -if the answer is correct. +In the list of incorrect answers to compare the student's answer with, 1 means +for each CODE reference incorrect answer, check the student's answer against +that CODE reference incorrect answer for messages even if the student answer is +correct. Default: 0 =item C 0 or 1 >>> @@ -45,9 +47,10 @@ =head2 AnswerHints =item C 0 or 1 >>> -1 means only perform the test -if the student answer is the -same type as the correct one. +In the list of incorrect answers to compare the student's answer with, 1 means +for each CODE reference incorrect answer, check the student's answer against +that CODE reference incorrect answer for messages only when the the student +answer the same type as the correct answer. Default: 1 =item C 0 or 1 >>> From b85a82776378f842b5658102d100626a69f64f2d Mon Sep 17 00:00:00 2001 From: Alex Jordan Date: Wed, 20 May 2026 21:32:49 -0700 Subject: [PATCH 2/2] improve handling of context flags with answerHints --- macros/answers/answerHints.pl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/macros/answers/answerHints.pl b/macros/answers/answerHints.pl index 6e625946fe..bb4264dc37 100644 --- a/macros/answers/answerHints.pl +++ b/macros/answers/answerHints.pl @@ -123,7 +123,6 @@ sub AnswerHints { my $hash = $context->{answerHash}; $context->{answerHash} = $ans; my $processPreview = $correct->getFlag('answerHintsProcessPreview', 0); - $context->{answerHash} = $hash; while (@_) { my $wrongList = shift; @@ -175,6 +174,7 @@ sub AnswerHints { } } } + $context->{answerHash} = $hash; return $ans; }, @_ @@ -194,6 +194,9 @@ sub Compare { $ans->{typeError} = 0; $ans->{ans_message} = $ans->{error_message} = ""; $ans->{score} = 0; + my $context = $self->context; + my $hash = $context->{answerHash}; + $context->{answerHash} = $ans; if ($self->address != $ans->{correct_value}->address) { $ans->{correct_ans} = $self->string; @@ -208,6 +211,7 @@ sub Compare { $self->cmp_preprocess($ans); $self->cmp_equal($ans); $self->cmp_postprocess($ans) if !$ans->{error_message} && !$ans->{typeError}; + $context->{answerHash} = $hash; return $ans->{score} >= 1; }