Create lua array from uservariable with multiple elements
Posted: Thursday 12 May 2016 18:48
Hi,
Does anyone have an idea on how to fill a lua array with multiple elements from 1 uservariable containing these elements?
If i define the array in lua it works fine:
local radi={}
radi[1]={'string 1',number1,'something else'}
radi[2]={'string 2',number2,'something else'}
print(radi[1][1]) --output = string 1
Now if i put the values in a uservariable of type string and fill like this
In gui:
Uservar1 = {'string 1',number1,'something else'}
Uservar2 = {'string 2',number2,'something else'}
local radi={}
local i = 1
while uservariables["Radi"..i] do
radi=uservariables["Radi"..i]
i = i + 1
end
print(radi[1][1]) --outputs all elements including {} = {'string 1',number1,'something else'}
I also tried filling the array like this:
In gui:
Uservar1 = 'string 1',number1,'something else'
Uservar2 = 'string 2',number2,'something else'
radi={uservariables["Radi"..i]}
I think i can probably get it to work to read the uservar as string and then loop through al parts and recreate it into an array, but that's not as nice as i want it too.
Gr,
Ronald
Does anyone have an idea on how to fill a lua array with multiple elements from 1 uservariable containing these elements?
If i define the array in lua it works fine:
local radi={}
radi[1]={'string 1',number1,'something else'}
radi[2]={'string 2',number2,'something else'}
print(radi[1][1]) --output = string 1
Now if i put the values in a uservariable of type string and fill like this
In gui:
Uservar1 = {'string 1',number1,'something else'}
Uservar2 = {'string 2',number2,'something else'}
local radi={}
local i = 1
while uservariables["Radi"..i] do
radi=uservariables["Radi"..i]
i = i + 1
end
print(radi[1][1]) --outputs all elements including {} = {'string 1',number1,'something else'}
I also tried filling the array like this:
In gui:
Uservar1 = 'string 1',number1,'something else'
Uservar2 = 'string 2',number2,'something else'
radi={uservariables["Radi"..i]}
I think i can probably get it to work to read the uservar as string and then loop through al parts and recreate it into an array, but that's not as nice as i want it too.
Gr,
Ronald