Quiz
Quiz
https://www.kwiksher.com/tutorials/Kwik4/Quiz.zip
The finished project will be similar to this:

Variables
the following variabels are created

- quiz_A
- quiz_B
- quiz_C
- quiz_question
- quiz_answer
- rightWrong
Dynamic Text Replacements
the variables are associated with the layer

layer | variable |
---|---|
tA | quiz_A |
tB | quiz_B |
tC | quiz_C |
tQuestion | quiz_question |
rightORWrong | rightWrong |
Buttons With External codes
each button has one external code as action

layer(button) | external codes |
---|---|
butA | checking correct or wrong |
butB | checking correct or wrong |
butC | checking correct or wrong |
Next | picking up a quizn |
-
Code > External Code
checking correct or wrong
For instance, this is used for butA. You can use code_but_A.lua, code_but_B.lua and code_but_C.lua
code_but_A.lua
if UI.quiz_A == UI.quiz_answer then
layer.rightORwrong.text = "Correct!"
else
layer.rightORwrong.text = "Wrong!"
end
-
Code > External Code
picking up a quiz for next
code_quizPickup.lua initializes the quiz and the answer again
UI.pickupQuestion()
picking up a quiz
code_pickQuiz.lua is added as external codes when the app runs.

UI.quiz = {
{"What is the color of the sky?","Pink", "Green", "Blue", "Blue"},
{"Which number is even?","3","4","5","4"}
}
--
UI.pickupQuestion = function()
local selectedQuestion = math.random(1, #UI.quiz)
UI.quiz_question = UI.quiz[selectedQuestion][1]
UI.quiz_A = UI.quiz[selectedQuestion][2]
UI.quiz_B = UI.quiz[selectedQuestion][3]
UI.quiz_C = UI.quiz[selectedQuestion][4]
UI.quiz_answer = UI.quiz[selectedQuestion][5]
-- update dynamic text
layer.tQuestion.text = UI.quiz_question
layer.tA.text = UI.quiz_A
layer.tB.text = UI.quiz_B
layer.tC.text = UI.quiz_C
-- clean up previous answer
layer.rightORwrong.text = ""
end
--
UI.pickupQuestion() -- initialization
-
Add External Code