WeBWorK Problems

scaffold.pl with answers tied across sections

scaffold.pl with answers tied across sections

by Alex Jordan -
Number of replies: 7

Is there a known technique to use scaffold.pl such that assessing the student's answer in section 2 depends on what they entered into section 1? If there is something that is known to work, that will sidestep my next question.

Attached is a silly exercise demonstrating something I tried to accomplish the above. I believe it works except that section 2 starts out with the green styling indicating it is already correct even before anything is submitted. Do we know what's causing that?

This reminds me a little bit of:
https://webwork.maa.org/moodle/mod/forum/discuss.php?d=8226
where I've found sometimes when I use scsaffold.pl a section is marked green that shouldn't be.





In reply to Alex Jordan

Re: scaffold.pl with answers tied across sections

by Alex Jordan -

I think I see the issue. The method that determines which section an answer name is in is concluding that all the multianswer answer blanks are in the first section where one of the multianswer answer blanks appear. I am looking into it, but I'm not sure how to change this, or if it's possible.

In reply to Alex Jordan

Re: scaffold.pl with answers tied across sections

by Alex Jordan -
In two places, scaffold.pl uses:
$PG_ANSWERS_HASH->{$name}->ans_eval

to determine if an answer evaluator has yet been assigned to the answer with name $name. This is all part of an indirect way for the code to determine which answer names are from the current scaffold section. The problem is that when there are multianswer blanks in multiple sections, when the evaluator is assigned to the first answer name, it is assigned to the rest as well. So to scaffold.pl, it appears as if all of the multianswer answer blanks come from the first section.

After inspecting $PG_ANSWERS_HASH repeatedly in a sample problem, I think I can replace `$PG_ANSWERS_HASH->{$name}->ans_eval` with:
defined($PG_ANSWERS_HASH->{$name}{response}{responses}{$name})

For example while in the first section, the hash $PG_ANSWERS_HASH->{AnSwEr0001}{response}{responses} is initialized with one key AnSwEr0001, but $PG_ANSWERS_HASH->{AnSwEr0002}{response}{responses} is an empty hash. Only once the second section is run is that hash given the key AnSwEr0002.

I tested this change with a few different configurations of multianswer questions (like two parts in one section, a third part in the next section) as well as with "normal" scaffold problems that don't use multianswer. And it works.

Does this proposed change raise any red flags? My problem with it is that I do not fully understand it. I do not know what mechanism is initializing theses hash keys, and that makes me nervous that there is some situation where the proposed change would break something.
In reply to Alex Jordan

Re: scaffold.pl with answers tied across sections

by Jaimos Skriletz -

Alex, here is another approach. I haven't used multianswers across sections, but instead store the students answer in a variable that I can then use in other answer checkers (or even output to the problem).

This approach basically takes advantage of variables are global in the safe compartment, but there might be a better approach to better scope the variables.

Though looks like allowing multianswers across scaffold sections would be useful, so that should probably be fixed, but here is an example that will work as is.

In reply to Jaimos Skriletz

Re: scaffold.pl with answers tied across sections

by Alex Jordan -

Thanks, this is a nice technique. I didn't think to assign variables from the main body while inside the checker. And this allows you to use thee previous section answers in subsequent section statements, hints, and solutions.

With the multianswer technique, I can easily put a message for the second part that says "This cannot be assessed until the first part is correct" or something like that. How would you do that with this method? We would need to access the score from the first answer hash, after that score is found. Would that be done with a post filter storing it to some global variable/array?

In reply to Alex Jordan

Re: scaffold.pl with answers tied across sections

by Jaimos Skriletz -
Notice how I set the variable `$student_r = 0` in the checker if the student hasn't either entered in an answer or an incorrect answer. So use this to generate any `Value->Error` messages in the second checker. Something like, `Value->Error('You must answer part 1 correct first') unless $student_r` should work.
In reply to Jaimos Skriletz

Re: scaffold.pl with answers tied across sections

by Glenn Rice -

Attached is a rework of Jaimos' problem that does this the way I have done this sort of thing in problems.  It uses the answer hash from the first part, instead of creating another global variable.

In reply to Glenn Rice

Re: scaffold.pl with answers tied across sections

by Glenn Rice -
Actually, there was a minor error in that first attachment. Comparing to the correct answer in the second checker doesn't work as it doesn't even look at the students answer to the second part. You probably get the idea though of the method though.

Attached is a corrected version.  Note that I also removed the custom checker on the first part to emphasize the versatility of this approach.