[LON-CAPA-users] Variables in libraries

lon-capa-users@mail.lon-capa.org lon-capa-users@mail.lon-capa.org
Sat, 19 Jul 2008 19:11:08 -0400


<font size=3D"2">I have been beating this for a couple of days, and am havi=
ng trouble understanding a) what is going on, and b) what I should do about=
 it:)<br><br>The basic idea is that I want to put various pieces of code in=
 libraries, which are then called from the main problems. Otherwise I end u=
p with the same code copied into many problems; when I want to make a chang=
e, I have to somehow find all those problems and change them. Of course, Lo=
nCapa doesn't have any search tools, so it is awkward to do this over my 70=
00 problems.<br><br>The problem I am having is understanding when my script=
 variables will work and when they won't. I know this has to do with the or=
der that the main problem html versus the libraries are parsed/evaluated/so=
mething.<br><br>In the example below, the status of the problem part SetupK=
ey within the FunctionCode library is retrieved fine. However, I do not see=
m to be able to retrieve the SetupKey submission at any time, either from w=
ithin the FunctionCode library (the ideal case) or from the MainProblem cod=
e.<br><br>So, 1) why doesn't this work? and <br>2) how would I obtain the s=
ubmission?<br><br>Thanks for any clues,<br>brew<br><br>MainProblem.problem:=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<br>&lt;problem&gt;<br>&=
lt;script type=3D"loncapa/perl"&gt;<br>$KeyCodeBeforeMain =3D &amp;EXT('use=
r.resource.resource.SetupKey.KeyCode.submission');<br>$whichScript=3D"Befor=
eMain";<br>&lt;/script&gt;<br><br>&lt;import id=3D"SetKey"&gt;FunctionCode.=
library&lt;/import&gt;<br><br>&lt;script type=3D"loncapa/perl"&gt;<br>$KeyC=
odeAfterMain =3D &amp;EXT('user.resource.resource.SetupKey.KeyCode.submissi=
on');<br>$whichScript=3D"AfterMain";<br>&lt;/script&gt;<br><br>&lt;part id=
=3Djunk&gt;<br>&lt;startouttext /&gt;<br>whichScript is {$whichScript} &lt;=
p/&gt;<br>statusKey is {$statusKey} &lt;p/&gt;<br>KeyCodeBeforeMain is {$Ke=
yCodeBeforeMain}&nbsp; &lt;p/&gt;<br>KeyCodeBefore is {$KeyCodeBefore}&nbsp=
; &lt;p/&gt;<br>KeyCodeAfter is {$KeyCodeAfter}&nbsp; &lt;p/&gt;<br>KeyCode=
AfterMain is {$KeyCodeAfterMain}&nbsp; &lt;p/&gt;<br><br>&lt;endouttext /&g=
t;<br>&lt;stringresponse answer=3D"yes" id=3D"stuff" type=3D"ci"&gt;<br>&lt=
;textline readonly=3D"no"&gt;<br>&lt;/textline&gt;<br>&lt;/stringresponse&g=
t;<br>&lt;/part&gt;<br>&lt;/problem&gt;<br><br><br>FunctionCode.library: =
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<br>&lt;library&gt;<b=
r><br>&lt;script type=3D"loncapa/perl"&gt;<br>$KeyCodeBefore =3D &amp;EXT('=
user.resource.resource.SetupKey.KeyCode.submission');<br>$statusKey =3D &am=
p;EXT('user.resource.resource.SetupKey.solved');<br>$whichScript=3D"BeforeS=
etupKey";<br>&lt;/script&gt;<br><br><br>&lt;part id=3D"SetupKey"&gt;<br>&lt=
;startouttext /&gt;<br>Enter the key<br>&lt;endouttext /&gt;<br>&lt;stringr=
esponse </font><font size=3D"2">id=3D"KeyCode" </font><font size=3D"2">answ=
er=3D"/.*/" type=3D"re"&gt;<br>&lt;textline readonly=3D"no"&gt;<br>&lt;/tex=
tline&gt;<br>&lt;/stringresponse&gt;<br>&lt;/part&gt;<br><br>&lt;script typ=
e=3D"loncapa/perl"&gt;<br>$KeyCodeAfter =3D &amp;EXT('user.resource.resourc=
e.SetupKey.KeyCode.submission');<br>$whichScript=3D"AfterSetupKey";<br>&lt;=
/script&gt;<br><br>&lt;/library&gt;<br><br>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D<br></=
font><BR>