WeBWorK Problems

popup in multianswer problem

popup in multianswer problem

by George Jennings -
Number of replies: 8
How does one include a popup in a multianswer problem? The pod doc
parserPopUp.pl says this is possible but I have tried several approaches and can't seem to make it work.
We're running pg version 2.4.9+
Regards,
George Jennings
In reply to George Jennings

Re: popup in multianswer problem

by Arnold Pizer -
Hi George,


In the list of techniques, look under Pop-up.

Arnie
In reply to Arnold Pizer

Re: popup in multianswer problem

by George Jennings -
Hi Arnie,

Thanks for your suggestion. The "Pop-up Lists For Many Questions With Common Answers" page does describe how to use pg functions to make questions that require students to answer multiple popup questions correctly to receive credit, but I was looking for something that uses MathObjects. The pod doc in parserPopUp.pl says

"You can use the PopUp menu object in MultiAnswer objects. This is the reason for the pop-up menu's ans_rule method (since that is what MultiAnswer calls to get answer rules)"

but I couldn't find an example anywhere in the documentation that says how to combine PopUp and MultiAnswer objects. All my attempts fail. Is there a way to combine PopUp and Multianswer objects?

George
In reply to George Jennings

Re: popup in multianswer problem

by Alex Jordan -
I am trying to do what George was trying here, and it looks like this was never fully resolved. Basically I have some background to a problem, and then I would like students to set up an inequality based on the background of the form:
Formula1 <= Formula2
I thought I would make math objects for the left and right sides, and a popup with options in the middle. (So that I can use a custom checker to allow students to enter it all in the opposite direction.) The documentation for parserPopUp.pl says that it can be used with parserMultiAnswer.pl, but I don't see how.

My most promising attempt so far has been to add a menu object to the MultiAnswer package as follows. I copied MultiAnswer's ans_rule object and inserted the command for how parserPopUp creates the dropdown menu. (Full code for my .pg problem is in an attached file.)
package MultiAnswer;
sub menu {
my $self = shift; my $size = shift || 20;
my $data = $self->{data}[$self->{part}];
my $name = $self->ANS_NAME($self->{part}++);
if ($data->class eq 'PopUp')
{return main::pop_up_list($data->{choices});
}
else {
return $data->named_ans_rule_extension($self->NEW_NAME($name),$size,@_)
if ($self->{singleResult} && $self->{part} > 1);
return $data->ans_rule($size,@_) unless $self->{namedRules};
return $data->named_ans_rule($name,$size,@_);
}
}
package main;


But this is not working. When I use this in my problem and call
\{$multians->ans_rule(10)\} \{$multians->menu\} \{$multians->ans_rule(10)\}
while having declared $multians as
$multians = MultiAnswer($left, $popup, $right)
I get the right structure (answer blank, popup menu with the right choices, answer blank) but I get the error messages below. These are not present if I change the second answer to a non-popup answer.
  • There is no answer evaluator for the question labeled AnSwEr0004 at /opt/webwork/pg/lib/WeBWorK/PG/Translator.pm line 1201
  • Error in Translator.pm::process_answers: Answer AnSwEr0004:
  • Unrecognized evaluator type || at /opt/webwork/pg/lib/WeBWorK/PG/Translator.pm line 1225
  • Error in Translator.pm::process_answers: Answer AnSwEr0004:
  • Answer evaluators must return a hash or an AnswerHash type, not type || at /opt/webwork/pg/lib/WeBWorK/PG/Translator.pm line 1230
  • Use of uninitialized value in addition (+) at (eval 10484) line 1707.

Full code for my .pg problem is in an attached file, if you would like to help me investigate this.

In reply to Alex Jordan

Re: popup in multianswer problem

by Davide Cervone -
This tuns out to be a problem with the PopUp when singleResult is used. It has to do with the fact that the MultiAnswer object needs to use answer "extensions" which don't have answer checkers assigned to them individually, but are used as part of another answer checker.

The PopUp will work properly if singleResult is 0, or if the PopUp is the first answer in the MultiAnswer object.

It is unlikely that you will be able to fix this yourself. I will need to work on that one myself, I'm afraid.

Davide
In reply to Davide Cervone

Re: popup in multianswer problem

by Alex Jordan -
OK, thanks for the insight. Since it will work if the popup comes first, I wonder if there is a possibility to use named answer fields and put the popup as the "first" answer even if it doesn't come first. I'll give this a try and post again if it works, although I'm not sure I can name a popup answer field. Also I believe I would want to manually adjust the correct_ans string if the idea works.
In reply to Alex Jordan

Re: popup in multianswer problem

by Davide Cervone -
It is an interesting idea, but I don't think it will work, either. This would require the PopUp to use a named answer extension, but that is going to be the same problem as you are currently having: the PopUp object doesn't implement them.
In reply to Davide Cervone

Re: popup in multianswer problem

by Christopher Heckman -
This also seems to be the case for Matrices ... I've been working the past few hours trying to get MultiAnswer to work with a Matrix object.
In reply to Christopher Heckman

Re: popup in multianswer problem

by Christopher Heckman -
I figured out what was going on. It was complicated.

I was creating a matrix starting with Value::Matrix, and usingĀ Davide Cervone's assign macro to modify the entries. This is a BAD THING; the modified matrix was causing the error message. When I created the matrix using other methods (setting up an array), the error message went away.

Once again, I'm posting my reply to help those who may find themselves in another situation.