I’m building a multiple choice test/quz app that needs to keep a record of answers.
I have a table that stores data for each question answered.
results = {
{answer = {}, correct, attempts},
{answer = {}, correct, attempts},
}
and I add data like
q = questionIndex
i = answer
results[q].answer[a] = results[q].answer[a] + 1
this works but but I’m planning to have 300+ to unlimited questions, so with my code above I need to copy the empty declaration {answer = {}, correct, attempts} 300 plus times in my source !
Is there a way around this?
The only solution I can think of is ‘losing’ the structure so it becomes a ‘flat array’ like results = {} and then just indexing the correct number of records to store the data.
What is the magic Lua solution? once I have the data on the App I plan to keep an online database of all users of the app