Doesn’t seem to be a way to do so without iterating, at least not with Lua.
also I just realized that using if table.find(comics,true) then
does not check that ALL of the values are true
, as long as just one of them is then the script will do then then
so that’s something to consider too
You will need to check if it finds false, then stop the execution.
table.find
will search for an element, and based on that information you can do what you’d like with it.
If it finds “false”, then you know all values aren’t true.
Nope, table.find()
will return where that value is placed inside the array, means that with only finding 1 of those, it will return the number where that value is stored, its not looping/iterating inside each value of the array, it just find if theres any true
or false
or string
“SadComic” in the table
wait so if there are 16 values I want to check are true
would I need to put 16 total true
in the table.find???
Nope, it requires a specific value, like if you are looking for “true” or for “comic651”, table.find() will return where a “true” or a “comic651” is placed.
Its totally wrong trying to find specific values inside the array by creating many table.find() hardcoded in the script
After some testing, the speed is approx. the same when being run 500,000 times.
However, table.find
is slightly faster if you’re looking for a performance boost.
okay i see, I just tried it and messed around with it and yeah I would have to check if there is a value that is false
like @Xacima had suggested
Oh!! I was exactly wondering about that, what is faster, then theres a slight difference being table.find faster, thank you for taking the time to test it!!
No worries.
Table functions was made for this purpose though, so it only makes sense that it has a reason behind it.
The code is also a lot shorter, + that slight performance boost.
As @Xacima alrady found, the improvement is not much, I still suggesting using the iteration, and use return instead of a variable
Yep! I am sticking with the way yall initially helped me out! c:
You can test yourself, but seems like iterating is faster when being ran 1 million times.
local Table = {true, false}
local Tick = tick()
for i = 1, 1000000 do
--if (table.find(Table, true)) then
--end
for _, Value in Table do
if (Value) then
end
end
end
local NewTick = tick()
print(NewTick - Tick)
You are right, the more iterations the for loop
becomes faster than the table.find()
Again it shouldn’t matter unless speed is absolutely necessary, in most cases it’s not.
But for those performance freaks (like me), it’s a solid option to pick a loop over the table functions.
instead of using a table to store the parts, you can also create a folder in workspace called Comics, put each comic into that folder, and iterate through the folder instead of having a ton of entries in the table.
local folder = workspace.Comics
for _,comic in pairs(folder:GetChildren) do
if comic.Value = true then
end
end
Personally I dont think than using folders and values saved into them its better idea than using server tables and modules to handle those tables. Its a common practice saving everything into folders, for me, I prefer using master tables in modules to arrange item or stat, inventory, almost anything, its faster to save a table by using DataStoreService than iterating a folder to create a table to save in DSS, and its easy to access all tables from any script if the tables are in modules
well I do have those “comics” in a folder already so maybe I could? I will try to see how this works and if its better, so thanks for the suggestion!
if I just checked the folder wouldn’t it be better than creating the table and then checking that since the folder is alread made in the game?
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.