AP Questionnaire
Documentation & support for AP Questionnaire.

Implementing Exam System
This example demonstrates how to set up an exam system by using the StartExam
export. This system is customizable, allowing you to define exam settings, shuffle questions, set minimum passing criteria, and more.
Step-by-Step Guide
Define the Exam Structure Use the
StartExam
export to define the exam structure. The parameters for the function are:title
: The title of the exam.Description
: A short explanation of the purpose of the exam.Logo
: A URL link to an image or logo representing the exam.Minimum
: The minimum number of questions required to pass.ShuffleQuestions
: A boolean to shuffle questions for each test-taker.AmountOfQuestionsToShow
: The number of questions to display during the exam.Questions
: An array of question objects, each containing:question
: The text of the question.answers
: A dictionary of possible answers.correctAnswer
: The key corresponding to the correct answer.
Add Questions Populate the
Questions
array with as many questions as needed. Each question object should have:A question text.
Multiple answers with unique keys.
The key corresponding to the correct answer.
Set Passing Conditions Define the number of minimum correct answers (
Minimum
) required to pass the exam. SetShuffleQuestions
totrue
to ensure that the questions are randomized for each candidate.Run the Exam Call the
StartExam
function with the defined parameters. The function will handle the exam flow, including question presentation, response validation, and determining whether the candidate has passed or failed.Handle Results Use the returned result (
true
for pass,false
for fail) to take appropriate action. For example:if startExam then print('Exam passed') else print('Exam failed') end
Example Code
local StartExam = exports['ap-questionnaire']:StartExam({
title = 'Police Exam',
Description = 'This exam is to be taken to see if you are able to become a police officer.',
Logo = 'https://www.policeinspire.co.uk/wp-content/uploads/2020/11/online-study-platform-vector.svg',
Minimum = 4, -- Minimum questions needed to pass.
ShuffleQuestions = true, -- Shuffle questions so they are not in order.
AmountOfQuestionsToShow = 5, -- Show only a selected number of questions.
Questions = {
[1] = {
question = 'What is the primary responsibility of a police officer?',
answers = { a = 'To enforce the law and maintain order', b = 'To create laws', c = 'To serve as a judge', d = 'To write constitutions' },
correctAnswer = 'a',
},
-- Add more questions as needed
},
})
if startExam then
print('Exam passed')
else
print('Exam failed')
end
Last updated