Is there a way to get multiple Variables in lua, using one command?
Something like multipleVars = SKIN:GetVariable('B0','B1','B2')
It is currently April 19th, 2024, 3:07 am
Getting multiple Variables in a single command.
-
- Posts: 919
- Joined: January 30th, 2017, 2:01 am
- Location: Greece
-
- Developer
- Posts: 22629
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Getting multiple Variables in a single command.
No, there is not.
-
- Developer
- Posts: 22629
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Getting multiple Variables in a single command.
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:
Which can be further shortened a bit with:
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...
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
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
-
- Posts: 919
- Joined: January 30th, 2017, 2:01 am
- Location: Greece
Re: Getting multiple Variables in a single command.
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:
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.)
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
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.)
-
- Developer
- Posts: 22629
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Getting multiple Variables in a single command.
Sounds fine. I'd probably shorten it a bit...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:and then work from that table.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
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.)
Code: Select all
multipleVars = {}
for i = 1, 100 do
table.insert(multipleVars , SKIN:GetVariable('B'..i))
if multipleVars[i] == '0' then break end
end
-
- Posts: 919
- Joined: January 30th, 2017, 2:01 am
- Location: Greece
Re: Getting multiple Variables in a single command.
Yea... I'm still figuring out the syntax :P I'm gonna go with that then, as it's cleaner.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
-
- Posts: 919
- Joined: January 30th, 2017, 2:01 am
- Location: Greece
Re: Getting multiple Variables in a single command.
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?
-
- Developer
- Posts: 22629
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Getting multiple Variables in a single command.
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.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?
I don't follow why you would care though. "i" is just going to end up as #multipleVars anyway.
-
- Posts: 919
- Joined: January 30th, 2017, 2:01 am
- Location: Greece
Re: Getting multiple Variables in a single command.
Oh yea.... I already have it as the length... right...