I have quite a complex logic problem in my app that is seriously stumping me. Essentially, I would like to design an algorithm which parses a list and retrieves a list item that contains a specific property eg. a word.
This is for my school planner application. I have an ‘homework assignments’ screen in which users can enter assignments. Additionally, I have a timetable screen which displays lessons that the student has for that particular day. What I would like to happen is when the user clicks a text item on the timetable, the app displays the tasks associated with that lesson.
Currently I am storing the homework assignments in a list like so:
So essentially, I want it so that that when the user clicks say ‘computer science’, they list viewer displays all the computer science tasks. So how could I design an algorithm which parses the assignments list and retrieves all the items that contain the words ‘computer science’ and then display them on the list viewer?
I am sorry if I have not explained this very clearly. Please feel free to ask for any clarification and I will try my best to explain. Any help would be greatly appreciated. Here is the link to the project:
A quick and dirty way to “make” a link is to have another list side by side to the Assignments list which stores the index of the selected item in Timetable in the same position of the Assignments list.
Example:
If a user selected “Computer Science”, you will store the index of this block
When the user enters the information of the Assignment you will insert an entry in the Assignments list and in the same time insert the saved index into the subject-assignment-reference list.
This way, you can show the assignments related to any subject.
Of course this does not save info in database but it will demonstrate how to link a subject to an assignment. You will need the other pieces of code of saving this extra list along with the assignment list to be always in synch.
I understand what you are suggestion however, I am not sure how it would work for my case. Currently the user enters the their lessons for the timetable which is then added to a big timetable list. Therefore, how could a list be created with just the lessons as your code has done?
When the user selects the lesson to add assignment to it then you grab the lesson name and save at instead of the index. Check for the lesson name instead of the lesson order number.
But my timetable is on a different screen, so say if you pick computer science, how would you search through the subjects list to find the assignments related to that subject. Right now it seems like you have suggested one integrated system but my application has two separate systems that need to be linked.
First of all you will have an app variable which means it is accessible from anywhere in the app and not limited to a screen.
Whenever one selects a subject, you will save this subject to the app variable, in my case, selectedSubject and then navigate to the Assignment screen.
If you use a list of objects as I demonstrated in the second example then every entry in the list of assignment has to values (the assignment info, and the subject it relates to)
This way you use the function I have in the example to view only the assignment related to the subject.
You’re setting the list viewer’s text items to a single value within your loop. Instead, you need to add that single value to a list and then once the loop has completed, set the list viewer’s text items to that list.
I’m not in front of a computer but if that doesn’t make sense, I can post a screenshot of the blocks later.
Almost! The in list get # block requires an actual number, an integer. But you’re giving it j which is a list item. So you end up telling Thunkable to see if list item # “Write an algorithm” contains “Computer Science” instead of what you actually want. You either have to use a count from 1 to x by 1 loop block or… what I would do here is to replace the in list get # block with just the j block. So it will say does j contain app variable selected subject.
By the way, it’s a very minor point but the = true block is optional here because the does contain block returns true or false. It’s also fine to just check if [does contain...] and leave off the = block.
The code is working however, there is a slight problem with the condition that checks if j is contained in ‘selected subject’. When the ‘timetable’ list was populated, each lesson was saved with its corresponding lesson number eg. Period 3: computer science. Therefore, even if the selected subject is computer science, it will return false as there is a ‘Period 3’ substring in front of it.
I think this will require the ‘get substring’ block however, I am not sure how to implement it. Thank you so much for your help!