WeBWorK Problems

by Olivia Henders -
Number of replies: 5
I'm working on a template problem that uses a ColumnTable to show a RadioButton object on the left and a graph image on the right. However, when I try running the code, I get this error:
Errors parsing PGML:
Error evaluating command: Can't locate object method "buttons" via package "True" (perhaps you forgot to load "True"?).

Here is the relevant code. Also, I am loading the parserRadioButtons.pl macro; I just haven't included it here.

$answer = RadioButtons(["True", "False"], "True"); ############################# # Main Text # Places the following information in column1 (the leftmost) of the layout table.$column1 = PGML::Format(<<END_PGML);
True or False: Is this a WeBWorK graph?

with quotes around the END_PGML in order to prevent variable substitution in the string being passed to PGML::Format. Without that, the $answer is being turned into is string form ("True", the correct answer) before PGML processes the string, and so the result is effectively [@ True->buttons() @]* which is where the error message you are getting is coming from. BTW, you should really use PGML::Format2() rather than PGML::Format() in most cases, since PG doubles all backslashes, and PGML::Format2() undoes that before processing the code. Without that, if you used any backslashes in your PGML (like for preventing some PGML command), then that would fail. In reply to Davide Cervone Re: RadioButtons in ColumnTable by Olivia Henders - That worked, thank you! Out of curiosity, why does this only work with single quotes? Seeing as single and double quotes are interchangeable pretty much everywhere else, it seems kind of strange. In reply to Olivia Henders Re: RadioButtons in ColumnTable by Davide Cervone - Single and double quotes are not interchangeable. Indeed, the difference between them is that variable substitution occurs within double quotes but not within single quotes. (Also, in double quotes, special characters can be obtained via backslashes, like \n for a newline, while only \' and \\ are interpreted within single quotes. But since PG doubles all backslashes in the PG file, this rarely comes up in PG directly.) Another way to phrase is is that single quotes enclose things you want to be exactly as you typed them, while double quotes are used around strings where you want perl to interpret special characters like \ and$.

by Olivia Henders -
Ah, makes sense! Sorry, I guess it just so happened that this wasn't an issue that came up until now. Thanks!