AP Scripts Documentation
  • AP Scripts Documentation
  • Scripts
    • AP Court
    • AP Government
    • AP Documents
    • AP AddonJob
    • AP Questionnaire
  • Recommended Phone
  • Script Snippets
  • Phone Integrations
Powered by GitBook
On this page
  • Implementing Exam System
  • Step-by-Step Guide
  • Example Code
  1. Scripts

AP Questionnaire

Documentation & support for AP Questionnaire.

PreviousAP AddonJobNextRecommended Phone

Last updated 3 months ago

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

  1. 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.

  2. 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.

  3. Set Passing Conditions Define the number of minimum correct answers (Minimum) required to pass the exam. Set ShuffleQuestions to true to ensure that the questions are randomized for each candidate.

  4. 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.

  5. 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