-
What do you want to achieve? I want to set an unknown number of variables to an unknown amount of values. I am in need of this because using the ‘unpack’ function it only returns what variables you have set it to.
-
What is the issue? I would like to use the string.find function on unpacking a table but I am facing some problems. It works if you concatenate all the variables together and then do string.find, but not otherwise.
local s1, s2, s3 = unpack({"first","second","third"})
print(string.find(s1..s2..s3,"second")) -- prints 6 11
I need to have this work for every amount of possible unpack returns. Something like
nthvariables = unpack({"hi","middle","bye"})
print(string.find(nthvariables,"hi"))
Where nthvariables could be 0, 1, or even 1,000 different unpacked values.
- What solutions have you tried so far? I tried doing this and other approaches but nothing seemed to work. I also tried doing a recursive function but again I ran into the problem of only seeing the first value of unpack when I passed it to a … in the function.
local function varset(C_String,Iteration,...)
local args = ...
local cumulativestring = C_String
cumulativestring = cumulativestring .. args[Iteration]
if Iteration < #args then
return varset(cumulativestring,Iteration+1,args)
else
return cumulativestring
end
end
This would have worked but … only resulted in the first unpacked value.