|
Post by andreos on Nov 14, 2019 16:30:42 GMT
I have a variable amount of snaps in a folder with the following name pattern: "name1.png", "name2.png" and so on.
I'd like to make a table with all these objects. However, the amount of objects may vary.
Could someone help, please?
|
|
|
Post by AnkuLua on Nov 14, 2019 22:53:43 GMT
|
|
|
Post by andreos on Nov 15, 2019 0:04:18 GMT
But how do I build the table automatically, knowing the number of objects on that folder may vary?
|
|
|
Post by AnkuLua on Nov 15, 2019 1:16:11 GMT
But how do I build the table automatically, knowing the number of objects on that folder may vary? FYR. num = 5 tab = {}
for i = 1, num do table.insert(tab, "name" .. i .. ".png") end for i, v in ipairs(tab) do print(v) end
|
|
|
Post by andreos on Nov 15, 2019 7:21:41 GMT
But how do I build the table automatically, knowing the number of objects on that folder may vary? FYR. num = 5 tab = {}
for i = 1, num do table.insert(tab, "name" .. i .. ".png") end for i, v in ipairs(tab) do print(v) end
Thanks!
|
|
|
Post by andreos on Nov 16, 2019 0:10:55 GMT
That partially solved my problem.
I have a table containing a variable amount of items.
table = {1, 2, 3, 4, 5, 6, 7, 8}
I need to perform the same actions for items 1~5 and then perform a different action for item 6 and above.
How can I do that in a loop including all elements of the table?
Exemple:
For items 1-5, it will print "hello". When the loop reaches the 6th element and forward, it'd print "hello there".
|
|
|
Post by AnkuLua on Nov 16, 2019 6:29:10 GMT
That partially solved my problem. I have a table containing a variable amount of items. table = {1, 2, 3, 4, 5, 6, 7, 8} I need to perform the same actions for items 1~5 and then perform a different action for item 6 and above. How can I do that in a loop including all elements of the table? Exemple: For items 1-5, it will print "hello". When the loop reaches the 6th element and forward, it'd print "hello there". Try this tab = {1, 2, 3, 4, 5, 6, 7, 8}
for i = 1, 5 do print("table element " .. tab[i]) end
for i = 6, #tab do print ("table upper element " .. tab[i]) end
|
|
|
Post by andreos on Nov 16, 2019 11:23:58 GMT
Thanks, again!
|
|