If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

True/False question type

From MoodleDocs

Database tables

Each true/false question creates two records in the quiz_answers table, one for the 'true' option, one for the 'false' option. The ids of these answers are stored in the 'trueanswer' and 'falseanswer' field of the quiz_truefalse table.

int(10) unsigned NOT NULL auto_increment,
int(10) unsigned NOT NULL default '0',
int(10) unsigned NOT NULL default '0',
id of the answer 'True' (not necessarily the correct answer).
int(10) unsigned NOT NULL default '0',
id of the answer 'False' (not necessarily the wrong answer).

It is important to distinguish between the answer 'True' and the correct answer. When setting up a true/false question the teacher decides whether the answer 'True' or the answer 'False' is the correct answer. So 'true' and 'false' here refer to the statement in the question text, not to the correctness of the answer.

The way Moodle stores which of the answers is the correct answer is via the 'fraction' field in the quiz_answers table. The correct answer has 'fraction' = 1, the wrong one has 'fraction' = 0.

Response storage

The response from the student in $state->responses[''] is the id of the answer chosen by the student. This then also gets stored in the 'answer' field in the quiz_states table.


$question->options object holds the data from the quiz_truefalse table and the ->answers property is an array of answers, indexed by the answer id. In the case of the true/false question $question->options->answers should of course be an array of only two answers.


True/false questions do not use the $state->options property.