hello guys ! I want to ask how can you make random selection of questions and answer in local DB, I’m making a quiz app but I want to shuffle everything just to have some challenge for the user. But it’s hard and I’m stuck.
I did try different approach like make a list and then shuffle it there but its not ideal because if I’m going to add question I need to put it again on a block text list and I think putting the questions in Local DB is much better way.
When you initialize the app, you can get all the questions from the LocalDB and put them in a list. That way, you are using questions from a LocalDB, but they are in a list and can be shuffled.
I’m not sure if you are using the term “Local DB” as used by Thunkable. If you are referring to the same component then you need to know that this is a temporary storage which does not retain data after the app is closed. This is mentioned in the documentation.
Start by creating a list that lists every row number in your Local DB. For example, if your Local DB is 5 rows long, this will create a list of the numbers 1-5. If your Local DB is 20 rows long, this will create a list of the numbers 1-20, etc. You can also create the variable question number, which is how we will point to the row on the Local DB whose question we’re displaying in the app.
@jane
The code is missing the main block. The one that makes use of the number as being the row number and retrieves the “quiz” from the Local DB. Without it, the app is just showing the numbers in a random fashion.
My focus here was on showing how to get a random, non-repeating series of numbers that can then be used to retrieve the information from that row number in the local DB.
I didn’t include the blocks saying ‘get cell at [column name] [question number]’ because it wasn’t the focus of this question, though of course you are correct in saying such blocks are needed to build a quiz app!
I’m glad you like it! The benefit of a forum like this is that we don’t have to independently figure out how to write the most efficient code - we can take inspiration from each other!