Intro / Apology: I’m very much a newbie. I’ve tried looking in various lua docs for my answers, but a couple of chapters in I always go from “yup, I knew that” to “I don’t know any of those words.” Even my questions may be phrased incorrectly, and I may be using most of these words wrong. Thanks for anyone patient enough to proceed…
I’d like to write a basic Quiz app using data pairs, e.g. States and Capitals. I’d like to store various different data sets in the app (eventually allowing the user to select from a list, but for starters I’m fine with manually changing the code to point to one in particular). I’d like to store each data set in its own tab in the app.
Question-Blob 1 is:
What format should I use in the file? I’ve seen things that look like:
Items = {
“this”,
“that”,
“the other”
}
But I want pairs of items that stay related to one another, e.g. “California, Sacramento”. I’d also like each item to have one or more additional fields, so that I can store a “score” or similar ranking on how well the user knows that item, e.g. “California, Sacramento, 5, 2” (where the user has seen that question 5 times, and got it right 2 times).
Could someone perhaps point me to a sample of what such a file would look like?
Question-Blob 2 is:
Once I have tabs called things like “State Capitals” and “U.S. Presidents”, how do I access one of these from my main program?
I’m assuming it’s best to start by reading one tab’s data into a table, and then working from that. Is that correct?
(And if I do it this way, could I later write back out to the data, such as to update the item scores?)
Is iterating through the data the best way to store it into a table, or is there a way to grab the whole list at once?
Is “table” even the right word for what I’d be creating? Is that how I’d store a list of x items, each item having y pieces of data associated with it?
To assign each item, I think I could write something like:
quiz = {}
quiz[“California”] = “Sacramento”
But how do I create a table where “California” is tied to several values that I can update independently (so that I can track the user’s score and progress)?
I’ve seen various combinations of square brackets, curly brackets, periods, and colons, and my head is swimming. I’ve looked in some of the wonderful sample apps posted here, but the ones I’ve found are complicated (though delightful) and I’m afraid I need something more basic.
I’d be ever so grateful if someone could point me to some ultra-basic examples or documentation, or earn bonus chocolate cookies by typing up a couple lines of ever-so-elegant code that points me in the right direction. Thanks much for any and all help!