Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to parserMultiAnswer breaks problems #450

Closed
drdrew42 opened this issue Jan 28, 2020 · 2 comments
Closed

Changes to parserMultiAnswer breaks problems #450

drdrew42 opened this issue Jan 28, 2020 · 2 comments

Comments

@drdrew42
Copy link
Member

Previously, @dpvc helped me write this modification to parserMultiAnswer.pl in order to pull a GeoGebra answerBox into a multiAnswer object. The update to the multi-answer library has broken all my problems written with this code.

The following code used to initiate a multi answer object with the first answerName matching that of the GeoGebra applet (answerBox); and after that, it would create answerNames according to the usual approach.

Can the old functionality be replicated under the modified version of parserMultiAnswer.pl?

#######################
### ggbApplet MultiAns
#######################
#
#  Make a subclass of MultiAnswer
#
package myMultiAnswer;
our @ISA = ('MultiAnswer');

sub new {
  my $self = shift;
  my $ma = $self->SUPER::new(@_);
  $ma->{part} = 1;
  $ma->{answerName} = 'answerBox';
  $ma->{id} = $MultiAnswer::answerPrefix.$ma->{answerName};
  $ma->{singleResult} = 1;
  $ma->{namedRules}  = 1;
  return $ma;
}

sub ANS_NAME {
  my $self = shift;
  my $i = shift;
  return ($i == 0 ? $self->{answerName} : $self->{id}.'_'.$i);
}

package main;

For one, it seems that answerName is no longer an appropriate hash key. Instead, answerNames keys to an array now?

Also, it seems that ANS_NAME has changed as well, and this replacement will no longer suffice.

The PG error message I'm seeing is:
---- main (eval 3679) 489 ------ Error in NAMED_ANSWER_RULE_EXTENSION: every call to this subroutine needs to have $options{answer_group_name} defined. For a single answer blank this is usually the same as the answer blank name. Answer blank name: MuLtIaNsWeR_answerBox_1

For testing purposes, an example problem that uses this method can be found here:

Contrib/CUNY/CityTech/Calculus/setExplore_-_Intermediate_Value_Theorem/geogebra-IVT.pg

@drdrew42
Copy link
Member Author

#######################
### ggbApplet MultiAns
#######################
#
#  Make a subclass of MultiAnswer
#
package myMultiAnswer;
our @ISA = ('MultiAnswer');

sub new {
  my $self = shift;
  my $ma = $self->SUPER::new(@_);
  $ma->{part} = 1;
  $ma->{answerName} = 'answerBox';
  $ma->{answerNames}{0} = $ma->{answerName};
  $ma->{id} = $MultiAnswer::answerPrefix.$ma->{answerName};
  $ma->{singleResult} = 1;
  $ma->{namedRules}  = 1;
  return $ma;
}

sub ANS_NAME {
  my $self = shift;
  my $i = shift;
  $self->{answerNames}{$i} = ($i == 0 ? $self->{answerName} : $self->{id}.'_'.$i);
  return $self->{answerNames}{$i};
}

package main;

Is this the best way to modify the original in order to accommodate the new answerNames cache?

If I've understood correctly, the answerNames cache expects the root name to live in the {0}th position and the other MuLtIaNsWeR_ blocks are built off of that first one?

@drgrice1
Copy link
Member

Although your modification will work, and even simpler approach that will work in the same way is to just delete your ANS_NAME method. The built in ANS_NAME method of the MultiAnswer object will work, and almost literally does the same thing. So use the following:

package myMultiAnswer;
our @ISA = ('MultiAnswer');

sub new {
  my $self = shift;
  my $ma = $self->SUPER::new(@_);
  $ma->{part} = 1;
  $ma->{answerName} = 'answerBox';
  $ma->{answerNames}{0} = $ma->{answerName};
  $ma->{id} = $MultiAnswer::answerPrefix.$ma->{answerName};
  $ma->{singleResult} = 1;
  $ma->{namedRules}  = 1;
  return $ma;
}

package main;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants