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.
Define the Exam Structure
Use the StartExam export to create your exam. You will need to define the following parameters: title – Name of the exam description – Short explanation of the exam logo – URL to an image/logo minimum – Minimum correct answers required to pass shuffleQuestions – Set to true to randomise questions amountOfQuestionsToShow – Number of questions shown per exam questions – Table of all exam questions
Add Questions
Populate the questions table with your exam content. Each question must include: question – The question text answers – A table of possible answers (with unique keys) correctAnswer – The key of the correct answer
Set Passing Conditions
Configure how the exam is graded: Set minimum to define how many correct answers are required to pass Enable shuffleQuestions if you want each attempt to be randomised
Run the Exam
Call the StartExam function with your configured data. Example:
local result = exports['ap-questionnaire']:StartExam({ title = "Driving Test", description = "Basic road knowledge exam", logo = "https://your-logo-url.com/image.png", minimum = 3, shuffleQuestions = true, amountOfQuestionsToShow = 5, questions = { { question = "What does a red light mean?", answers = { a = "Stop", b = "Go", c = "Slow down" }, correctAnswer = "a" } } })Handle Results
Use the returned result to determine if the player passed or failed. Example:
if result then print('Exam passed') else print('Exam failed') endRestart Server
Restart your server to apply all changes.
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