Page 1 of 1
Getting multiple Variables in a single command.
Posted: September 30th, 2017, 2:31 pm
by kyriakos876
Is there a way to get multiple Variables in lua, using one command?
Something like multipleVars = SKIN:GetVariable('B0','B1','B2')
Re: Getting multiple Variables in a single command.
Posted: September 30th, 2017, 3:06 pm
by jsmorley
No, there is not.
Re: Getting multiple Variables in a single command.
Posted: September 30th, 2017, 3:35 pm
by jsmorley
You can assign the value of multiple variables in one command in Lua, and you can at least "shorten" the overall length by using a function like this:
Code: Select all
function Initialize()
myVar1, myVar2, myVar3, myVar4 = v('Var1'), v('Var2'), v('Var3'), v('Var4')
end
function Update()
print(myVar1, myVar2, myVar3, myVar4)
end
function v(varName)
return SKIN:GetVariable(varName)
end
Which can be further shortened a bit with:
Code: Select all
function Initialize()
function v(varName) return SKIN:GetVariable(varName) end
myVar1, myVar2, myVar3, myVar4 = v('Var1'), v('Var2'), v('Var3'), v('Var4')
end
function Update()
print(myVar1, myVar2, myVar3, myVar4)
end
But by hook or by crook, you are going to have to distinctly call SKIN:GetVariable() for each one you want to get. There just is no SKIN:GetVariable('Var1', 'Var2', 'Var3', 'Var4'). I'm not sure I see any great value trying to jam it all in one command, but to each his own...
Re: Getting multiple Variables in a single command.
Posted: September 30th, 2017, 4:51 pm
by kyriakos876
Yea, I decided that I don't want to call SKIN:GetVariables() 100 times so I made a table and stored them in
So, I have B0=1, B1=1, B2=1, ..., B100=1 and I get them into lua with:
Code: Select all
multipleVars = {}
local i = 0
while i < 100 do
multipleVars [i] = SKIN:GetVariable(string.format('B%s', i))
table.insert(multipleVars , multipleVars [i])
if multipleVars [i] == '0' then break end
i = i + 1
end
and then work from that table.
The
if multipleVars [i] == '0' then break end is there because I'm searching 100 variables and stop when I find 0 in case you were wondering.(Obviously, I just mentioned it because it's irrelevant to the post.)
Re: Getting multiple Variables in a single command.
Posted: September 30th, 2017, 5:16 pm
by jsmorley
kyriakos876 wrote:Yea, I decided that I don't want to call SKIN:GetVariables() 100 times so I made a table and stored them in
So, I have B0=1, B1=1, B2=1, ..., B100=1 and I get them into lua with:
Code: Select all
multipleVars = {}
local i = 0
while i < 100 do
multipleVars [i] = SKIN:GetVariable(string.format('B%s', i))
table.insert(multipleVars , multipleVars [i])
if multipleVars [i] == '0' then break end
i = i + 1
end
and then work from that table.
The
if multipleVars [i] == '0' then break end is there because I'm searching 100 variables and stop when I find 0 in case you were wondering.(Obviously, I just mentioned it because it's irrelevant to the post.)
Sounds fine. I'd probably shorten it a bit...
Code: Select all
multipleVars = {}
for i = 1, 100 do
table.insert(multipleVars , SKIN:GetVariable('B'..i))
if multipleVars[i] == '0' then break end
end
Re: Getting multiple Variables in a single command.
Posted: September 30th, 2017, 5:24 pm
by kyriakos876
jsmorley wrote:Sounds fine. I'd probably shorten it a bit...
Code: Select all
multipleVars = {}
for i = 1, 100 do
table.insert(multipleVars , SKIN:GetVariable('B'..i))
if multipleVars[i] == '0' then break end
end
Yea... I'm still figuring out the syntax :P I'm gonna go with that then, as it's cleaner.
Re: Getting multiple Variables in a single command.
Posted: September 30th, 2017, 5:36 pm
by kyriakos876
Is the i in the for loop temporary just for the loop? I mean, when I try to extract the i I'm getting nil. Should I save it in a variable before break if I want to use it somewhere else?
Re: Getting multiple Variables in a single command.
Posted: September 30th, 2017, 5:42 pm
by jsmorley
kyriakos876 wrote:Is the i in the for loop temporary just for the loop? I mean, when I try to extract the i I'm getting nil. Should I save it in a variable before break if I want to use it somewhere else?
The "i" is just for the loop. If you want to save it, you are back to your original method with i = i + 1 and all that.
I don't follow why you would care though. "i" is just going to end up as #multipleVars anyway.
Re: Getting multiple Variables in a single command.
Posted: September 30th, 2017, 5:46 pm
by kyriakos876
Oh yea.... I already have it as the length... right...