WeBWorK Problems

parserPopup.pl and randomizing choices

parserPopup.pl and randomizing choices

by Murphy Waggoner -
Number of replies: 4
I was trying to follow
http://webwork.maa.org/pod/pg_TRUNK/macros/parserPopUp.pl.html
to create a popup question with randomized choices. I see the same documentation in

However, the code for the randomization results in a rendering error, even when I copy the line of code from the documentation. The relevant lines are highlighted.

Thanks.

----------------------------------------------
The first code below works. The second code gets an error saying the the correct answer needs to be in the list.

--------------------------------------
Working code
--------------------------------------
DOCUMENT();
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"parserPopUp.pl",
"PGcourse.pl"
);
TEXT(beginproblem());

$showPartialCorrectAnswers = 0;

##########################
# Setup

Context("Numeric");

$radio1 = PopUp(
[
"First Item",
"Random 1","Random 2","Random 3",
"Last Item"
],
"Random 3"
); # Correct answer
 

##########################
# Main text

Context()->texStrings;
BEGIN_TEXT
Pick one \{ $radio1->menu() \} .
END_TEXT
Context()->normalStrings;


##########################
# Answer evaluation

ANS( $radio1->cmp() );

ENDDOCUMENT();

------------------------------------------
Code that doesn't work with error
------------------------------------------
DOCUMENT();
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"parserPopUp.pl",
"PGcourse.pl"
);
TEXT(beginproblem());

$showPartialCorrectAnswers = 0;

##########################
# Setup

Context("Numeric");

$radio1 = PopUp(
[
"First Item",
["Random 1","Random 2","Random 3"],
"Last Item"
],
"Random 3"
); # Correct answer
 

##########################
# Main text

Context()->texStrings;
BEGIN_TEXT
Pick one \{ $radio1->menu() \} .
END_TEXT
Context()->normalStrings;


##########################
# Answer evaluation

ANS( $radio1->cmp() );

ENDDOCUMENT();
In reply to Murphy Waggoner

Re: parserPopup.pl and randomizing choices

by Alex Jordan -
HI Murphy,

Is this your WW server?
http://math.simpson.edu/webwork2/

If so, it is using version 2.10. The changes to parserPopUp that make that kind of randomization possible are more recent. I'm not sure when they happened, but they work on 2.13.

In reply to Alex Jordan

Re: parserPopup.pl and randomizing choices

by Murphy Waggoner -
Yes, that is our server.

Are the changes that make that kind of randomization possible isolated in parserPopUp.pl? If so, can I just copy the newest version of it to \macros for my course until we update our server?

In reply to Murphy Waggoner

Re: parserPopup.pl and randomizing choices

by Davide Cervone -
The changes to parserPopUp.pl seem to be isolated to that file. But parserPopUp.pl relies on the MathObjects String class, and that was last modified in the summer of 2015. It looks like version 2.10 was released in January 2015, with an update to 2.10+ in November 2015, so it may be that some of the changes in the summer of 2015 are missing from your server (depending on when your copy of 2.10 was obtained). Since the String object is defined in a .pm not a .pl file, you won't be able to replace it without access to the server (and restarting it after the change). But it probably will work if you just upload the current parerPopUp.pl file. Give it a try and see.
In reply to Murphy Waggoner

Re: parserPopup.pl and randomizing choices

by Alex Jordan -
I can't say for sure. They may be tied with certain changes to PGML.pl that made it easier to use PopUp questions in PGML in the first place. And those changes to PGML.pl may have been concurrent with some lower-level things too.

2014 and 2015 saw a lot of edits to parserPopUp.pl:
https://github.com/openwebwork/pg/commits/master/macros/parserPopUp.pl
and if any of those are tied to other developments, it could be trouble to just bring in the new version without a full upgrade.