Hello. I have a table, and I want to loop it like that:
Let me explain better. When the event fired, A will be table[3], C will be table[2], and B will be table[1]. And the new situation of the table will be {B,C,A}.
How can I do that? With metatables? Or table functions?
Thanks for the reading!
I meant, when the event fired, {A,B,C} will be {B,C,A}. If happens again, then it will be {C,A,B}. Again then {A,B,C}. So, table[index] will change positions with table[index+1] (the next position) if there is not next position(if it’s table[1]), then it will be last table. Example: {A,B,C}, event fired, {B,C,A}. Event fired, {C,A,B}…
local T = {"A","B","C"}
for i = #T,1,-1 do
local T2 = {}
for _,L in pairs(T) do
if L ~= T[i] then
table.insert(T2,L)
end
end
print(T[i],table.unpack(T2))
end