MyOpenMath Help

Common options to all types

All question types can support these options:

Hints

For a single question (not multipart), to use hints, in the common control (or question control) section define the array $hints where:

$hints[attempt number] = "hint text"

For example:

$hints[0] = "This will show on first display"
$hints[1] = "This will show on second attempt (after 1 missed attempt)"
$hints[2] = "This will show on third and subsequent attempts, since no later values have been defined"

It is fine, for example, to not define $hints[0] if you want nothing to display initially.

Then in the question text, place the location of the hint using the variable $hintloc.

In multipart questions, you can follow the process above if you just want a single strand of hints for the entire problem. If you want per-part hints, define the $hints array as:

$hints[question part number][attempt number] = "hint text"

Then in question text, place each hint using $hintloc[question part number]

To have the hint to display based on a set of previous answers, you can use:

$hints[question part number][attempt number] = array("hint text", [part num1, part num 2])

This will display the hint after all the parts listed have had the required attempts or are correct.

To override the default Hint: text, set $hintlabel.

Help references

To provide help of some sort for a question (typically, links to videos, book references, etc), define $helptext in the common control section. Any text assigned to this variable will show at the bottom of the question. The display of this text is controlled by the same "show hints?" option that controls the display of hints described above.

Referencing Student Answers

To create multipart questions that are graded on consistency, or to create a set of lab-type problems that rely on student-provided data, you can reference students' previous answers in your question code. You will only be able to reference the student answer to some question types

Notes (important!):

1) If the student has not answered the question, then $stuanswers[N] === null, with the exception of drop-down select questions, where $stuanswers[N] == "NA" if no selection is made. If used in an equation, it will take on the value 0. To prevent divide-by-zero errors and to prevent students from exploiting this, it is highly recommended that you do something like:

$a = $stuanswers[$thisq][0]
$a = rand(1,100) if ($a===null)

Perhaps also include: $warning = "You MUST answer question 1 before this question" if ($a===null), then put $warning in the question text.

2) If you use $stuanswers in your $answer, $showanswer will generally not be defined. If you follow the advice in #1 above, then your $showanswer will reflect the random number assigned to $a. For this reason, it is highly recommended that you custom define the $showanswer.

3) If using the $stuanswers array in a string or in the Question Text, you must enclose it with curly brackets: Your answer was {$stuanswers[0][0]}. If using it directly in a calculation, enclose it in parentheses just to be safe.

4) $stuanswers[$thisq] is defined for question scoring, but may not be for question display.

5) You can use the function getstuans($stuanswers,N,P) to retrieve a student answer value. This method bypasses some strange things that happen when there is a multipart question with only one part, so is recommended.

6) You can use the function stuansready($stuanswers,$thisq,[p1,p2,...]) to determine if the parts have been answered, instead of checking for null.

Other Reference Variables

A few other special purpose variables can be referenced:

Reusing Code

You can import in the Common Control code from another question using

includecodefrom(questionid)

where questionid is the ID number of the question you want to import the code of. In the source question, the variable $included will automatically be set to true when the question has been included, so it can be used to determine if the question has been imported into another question, or is running independently.

For example, in the master/source question, you might use the code:

if (!$included) {
 $type = rand(0,4)
}
do stuff here

In a question using this code, you could limit to a specific type using:

$type = 0
includecodefrom(1234)

Question text can be also brought in from another question by using

includeqtextfrom(questionid)

somewhere in the Question Text portion of the question.

Teacher Notes

In the question text, you can add a note that will only be viewable by the teacher while grading. Do this by wrapping the teacher note in the [teachernote] shortcode like this: [teachernote]This is the note[/teachernote]

Hiding/Toggling content

If you need to hide content from view, you can wrap it in <div class="hidden"></div>. Be aware the content is still in the page, so a student can still view the hidden content using the browser inspector, so don't use this to hide secret info, but it can be helpful if you need to hide an answerbox that is being populated by some other means.

If you want to toggle a block of content, one option for shorter content is to use forminlinebutton. For longer content, you can wrap the content in a block using <div data-toggler="Title for button"></div>. That will hide the wrapped content, and add a button with the specified title for toggling the content. You can optionally add a data-toggler-hide attribute as well if you want a different button label once the content is showing.