[LON-CAPA-users] Variables in libraries

Felicia Berryman lon-capa-users@mail.lon-capa.org
Fri, 25 Jul 2008 16:47:14 -0400


Hi Brew,

Just making your example simpler.  You can use my text below to create a 
bug report if no one has any ideas on how to make this work.

$Key displays after submission using problem code below:
---------------------------------------------
<problem>
<script type="loncapa/perl">
$Key =&EXT('user.resource.resource.PART-ID.SUBMISSION-ID.submission');
</script>

<part id="PART-ID">
<startouttext />Enter something<endouttext />
<stringresponse answerdisplay="Got it" answer="/.*/" id="SUBMISSION-ID" 
type="re">
<textline readonly="no"></textline>
</stringresponse>
</part>

<startouttext /><p>You entered $Key</p><endouttext />
</problem>
---------------------------------------------

$Key doesn't display after submission using problem code below:
---------------------------------------------
<problem>
<script type="loncapa/perl">
$Key =&EXT('user.resource.resource.PART-ID.SUBMISSION-ID.submission');
</script>

<part id="PART-ID">
<import>brew.library</import>
</part>

<startouttext /><p>You entered $Key</p><endouttext />
</problem>
---------------------------------------------
Where brew.library is:
---------------------------------------------
<library>
<startouttext />Enter something<endouttext />
<stringresponse answerdisplay="Got it" answer="/.*/" id="SUBMISSION-ID" 
type="re">
<textline readonly="no"></textline>
</stringresponse>
</library>
---------------------------------------------

Felicia

Robert_Brewington@er.monroe.edu wrote:
> I have been beating this for a couple of days, and am having trouble 
> understanding a) what is going on, and b) what I should do about it:)
> 
> 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 
> up with the same code copied into many problems; when I want to make a 
> change, I have to somehow find all those problems and change them. Of 
> course, LonCapa doesn't have any search tools, so it is awkward to do 
> this over my 7000 problems.
> 
> 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 order that the 
> main problem html versus the libraries are parsed/evaluated/something.
> 
> In the example below, the status of the problem part SetupKey within the 
> FunctionCode library is retrieved fine. However, I do not seem to be 
> able to retrieve the SetupKey submission at any time, either from within 
> the FunctionCode library (the ideal case) or from the MainProblem code.
> 
> So, 1) why doesn't this work? and
> 2) how would I obtain the submission?
> 
> Thanks for any clues,
> brew
> 
> MainProblem.problem: =========================================
> <problem>
> <script type="loncapa/perl">
> $KeyCodeBeforeMain = 
> &EXT('user.resource.resource.SetupKey.KeyCode.submission');
> $whichScript="BeforeMain";
> </script>
> 
> <import id="SetKey">FunctionCode.library</import>
> 
> <script type="loncapa/perl">
> $KeyCodeAfterMain = 
> &EXT('user.resource.resource.SetupKey.KeyCode.submission');
> $whichScript="AfterMain";
> </script>
> 
> <part id=junk>
> <startouttext />
> whichScript is {$whichScript} <p/>
> statusKey is {$statusKey} <p/>
> KeyCodeBeforeMain is {$KeyCodeBeforeMain}  <p/>
> KeyCodeBefore is {$KeyCodeBefore}  <p/>
> KeyCodeAfter is {$KeyCodeAfter}  <p/>
> KeyCodeAfterMain is {$KeyCodeAfterMain}  <p/>
> 
> <endouttext />
> <stringresponse answer="yes" id="stuff" type="ci">
> <textline readonly="no">
> </textline>
> </stringresponse>
> </part>
> </problem>
> 
> 
> FunctionCode.library: ===========================================
> <library>
> 
> <script type="loncapa/perl">
> $KeyCodeBefore = &EXT('user.resource.resource.SetupKey.KeyCode.submission');
> $statusKey = &EXT('user.resource.resource.SetupKey.solved');
> $whichScript="BeforeSetupKey";
> </script>
> 
> 
> <part id="SetupKey">
> <startouttext />
> Enter the key
> <endouttext />
> <stringresponse id="KeyCode" answer="/.*/" type="re">
> <textline readonly="no">
> </textline>
> </stringresponse>
> </part>
> 
> <script type="loncapa/perl">
> $KeyCodeAfter = &EXT('user.resource.resource.SetupKey.KeyCode.submission');
> $whichScript="AfterSetupKey";
> </script>
> 
> </library>
> 
> ==========================================================
> 
> _______________________________________________ LON-CAPA-users mailing 
> list LON-CAPA-users@mail.lon-capa.org 
> http://mail.lon-capa.org/mailman/listinfo/lon-capa-users

-- 
Felicia Berryman
Instructional Systems
Michigan State University
(517)432-7326
LON-CAPA Technical Support Available at:
    http://www.loncapa.msu.edu - MSU Users
    http://www.help.lon-capa.org - General