How do I...?

Make a Basic Quiz/Testing Application

As an example, we will create a two page test, and a third page to display the results:

  1. Create a project with three pages.

  2. Insert the following code in the Global Functions:

--Each of the following tables contains a question, and 4 answers:
Q_01 = {Question="How many legs does a three leg'd dog have?", A1="One", A2="Two", A3="Four", ACorrect="Three"};
Q_02 = {Question="How many legs does a one leg'd cat have?", A1="Three", A2="Two", A3="Four", ACorrect="One"};
Correct={Q1="",Q2=""};

  1. On Page1, create one paragraph object, and four button objects.

  2. In the On Preload event of Page1, insert the following code:

Paragraph.SetText("Paragraph2", Q_01.Question);
Button.SetText("Button1", Q_01.A2);
Button.SetText("Button2", Q_01.A1);
Button.SetText("Button3", Q_01.ACorrect);
Button.SetText("Button4", Q_01.A3);

  1. Insert the following code into the On Click event of Button1:

Correct.Q1 = "InCorrect";
Page.Navigate(PAGE_NEXT);

  1. Insert the following code into the On Click event of Button2:

Correct.Q1 = "InCorrect";
Page.Navigate(PAGE_NEXT);

  1. Insert the following code into the On Click event of Button3:

Correct.Q1 = "Correct";
Page.Navigate(PAGE_NEXT);

  1. Insert the following code into the On Click event of Button4:

Correct.Q1 = "InCorrect";
Page.Navigate(PAGE_NEXT);

  1. On Page2, create one paragraph object, and four button objects.

  2. In the On Preload event of Page2, insert the following code:

Paragraph.SetText("Paragraph2", Q_02.Question);
Button.SetText("Button1", Q_02.A3);
Button.SetText("Button2", Q_02.A2);
Button.SetText("Button3", Q_02.A1);
Button.SetText("Button4", Q_02.ACorrect);

  1. Insert the following code into the On Click event of Button1:

Correct.Q2 = "InCorrect";
Page.Navigate(PAGE_NEXT);

  1. Insert the following code into the On Click event of Button2:

Correct.Q2 = "InCorrect";
Page.Navigate(PAGE_NEXT);

  1. Insert the following code into the On Click event of Button3:

Correct.Q2 = "InCorrect";
Page.Navigate(PAGE_NEXT);

  1. Insert the following code into the On Click event of Button4:

Correct.Q2 = "Correct";
Page.Navigate(PAGE_NEXT);

  1. Create one paragraph object on the last page of your project.

  2. Insert the following code into the On Preload event of the last page:

string_correct="";
correct = 0;
possible = 0;
for j,k in pairs(Correct) do
    possible = possible + 1;
    if k == "Correct" then
        correct = correct + 1;
    end
end

Paragraph.SetText("Paragraph2",
"Question 1: " .. Correct.Q1 .. "\r\n" ..
"Question 2: " .. Correct.Q2 .. "\r\n" ..
"You answered correctly " .. correct .. " out of " .. possible .. " possible questions for a score of " .. ((correct/possible)*100) .. "%."
);