darkvrn
(darkvrn)
February 24, 2023, 10:59pm
1
cant wrap my head around why its doing this, maybe its cuz im extremely tired rn but yeah
table
cooltable = {
Example1 = {
thing = "example1";
},
Example2 = {
thing = "example1";
},
Example3 = { --skips this table
thing = "example3";
},
Example4 = {
thing = "example4";
},
},
loop
-- for this post lets just say thestring is "example3"
local thestring = "example3"
for i,v in pairs(Module.cooltable) do
print(v.thing)
print(thestring)
if v.thing == thestring then
print(v)
return
else
print("") --just to seperate output for better reading of the prints
end
end
output
example1 --v.thing
example3 --thestring
example2 --v.thing
example3 --thestring
example4 --v.thing
example3 --thestring
DataSigh
(DataSigh)
February 24, 2023, 11:10pm
3
What is it supposed to do instead? Looks like it’s working properly
1 Like
darkvrn
(darkvrn)
February 24, 2023, 11:15pm
4
its skipping Example3
output is
example1 --v.thing
example3 --thestring
example2 --v.thing
example3 --thestring
example4 --v.thing
example3 --thestring
instead of
example1 --v.thing
example3 --thestring
example2 --v.thing
example3 --thestring
example3 --v.thing
example3 --thestring
Example3 -- cuz of the conditioned print
DataSigh
(DataSigh)
February 24, 2023, 11:15pm
5
That’s because you have this if v.thing == thestring then
and set it to return
1 Like
darkvrn
(darkvrn)
February 24, 2023, 11:18pm
6
oops, forgot about that return in the other reply
it would still print v tho and the Example4 stuff wouldnt print aswell
DataSigh
(DataSigh)
February 24, 2023, 11:21pm
7
Oh, that’s because dictionaries loop in an unordered way. If you want it to be ordered loop you need to have it like this:
cooltable = {
[1] = {
thing = "example1";
},
[2] = {
thing = "example1";
},
[3] = {
thing = "example3";
},
[4] = {
thing = "example4";
},
},
1 Like
darkvrn
(darkvrn)
February 24, 2023, 11:33pm
8
for some reason i kept another few lines of code under the v.thing if statement that was matching strings and returning
lack of sleep is getting to me
system
(system)
Closed
March 10, 2023, 11:34pm
9
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.