File:  [LON-CAPA] / loncom / html / adm / help / tex / Authoring_Daxe_Variables.tex
Revision 1.1: download - view: text, annotated - select for diffs
Wed Mar 27 16:39:44 2024 UTC (3 months, 1 week ago) by raeburn
Branches: MAIN
CVS tags: version_2_12_X, version_2_11_4_msu, HEAD
- Contents of tutorial/getting_started.xhtml divided into 11 .tex files
- Two links added to "Help" dropdown in Daxe Editor:
   one to Daxe FAQ,
   one to LON-CAPA Math Syntax (describes lm tag).
- Existing "Getting Started" link points to composite of 9 .hlp files
  to facilitate multilingual support.

\label{Authoring_Daxe_Variables}

\textbf{Creating a Problem with Randomized Values}

Some randomization can easily be achieved with a radio button response, 
by setting thei\texttt{randomize} attribute to 'yes', setting the
\texttt{max} attribute to a maximum number of displayed foils, 
and creating more foils than will be displayed.

With a numerical response, it is necessary to create variables with random values.  
This can be done with a Perl script. Such a script is created by inserting a
\texttt{script} element (in the \textit{Block} menu) and setting its
\texttt{type} attribute to '\texttt{loncapa/perl}'.

Here is a little cookbook for randomizing values with a Perl script:
\begin{itemize}
  \item To set variable a to the value 1:

\texttt{\$a = 1;}

  \item To set variable a to the value 'text':

\texttt{\$a = 'text';}

Note that single quotes take the value literally, while double quotes replace variables by their values.

  \item To pick a random number between 1 and 5 (included), with a step of 0.5:

\texttt{\$a = random(1, 5, 0.5);}

(the step can be omitted to use a step of 1)

  \item To chose a value randomly in a list of text entries:

\begin{verbatim}
@list = ('one', 'two', 'three');
$n = random(1, scalar(@list));
$a = choose($n, @list);\end{verbatim}

  \item Math operators:

\texttt{+, -, *, /, **, \%}

  \item Math functions:

\texttt{sin, cos, tan, asin, acos, atan, atan2, log, log10, exp, pow, sqrt, abs, sgn, erf, erfc, ceil, floor, min, max, factorial, sinh, cosh, tanh, asinh, acosh, atanh}

  \item Comments:

\texttt{\# This is a comment.}
\end{itemize}

Once created in a script, variables can be used anywhere afterwards, still prefixed with
\texttt{\$}. In particular, a numerical response answer can be set to a variable.

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>