Compare and Print in Lua?

57 Views Asked by At

I like to compare and print, I have parent child relationship, where I have category,group,questions and sub-questions Each sub-question is part of a question, each question is part of a group and each group is part of a category.

my problem is that my category name prints on each group, I like to set if they have the same name to category not to print it but to show the next one when needed.

Let me show you what I mean:

a = category
b = group
q,e,r =questions
t = sub-question

(Category Name) Cat 1
(Group Name)Group 1 (part of Cat 1)
(Question Name) Question 1  (part of Group 1)
                Question 2  (part of Group 1)
                Question 3  (part of Group 1)
 (Sub question) -Sub-question 1 (part of Question3)

 (Group Name)Group 2 (part of Cat 1)
 (Question Name) Question 1  (part of Group 2)
                Question 2  (part of Group 2)
                Question 3  (part of Group 2)
 (Sub question) -Sub-question 1 (part of Question3)

 (Category Name) Cat 2
 (Group Name)Group 3 (part of Cat 2)
 (Question Name) Question 1  (part of Group 3)
                Question 2  (part of Group 3)
                Question 3  (part of Group 3)
 (Sub question) -Sub-question 1 (part of Question3)

The result is:
 Cat 1
 Group 1
 Question 1
 Question 2
 Question 3
 Sub-question 1
 **Cat 1 *(this is what I like to skip)**
 Group 2
 Question 1
 Question 2
 Question 3
 Sub-question 1
 Cat 2
 Group 3
 Question 1
 Question 2
 Question 3
 Sub-question 1

If they are from the same Category don`t print it twice or 100 times just once.

1

There are 1 best solutions below

0
On

t = { jek="1kat", jek="1kat", jek="1kat", pek="2kat", trek="3kat", cetrek="4kat", petrek="5kat", petrek="5kat", sesrek="6kat", sedmrek="7kat"}

previous = k

for ki,k in pairs(t) do

if (k~=previous) then

print(k)

end

end

thx for all ur help!!