I've been using a slightly modified script by jsmorely to obtain the height of an image from a meter and return the value as a variable.The script works fine for one image but it is my intention to have up to nine images at once.I am trying to modify the script to accommodate this but I keep getting "ERROR: (01:02:24.086) Script: Script2.lua:25: 'end' expected (to close 'function' at line 14) near '<eof>'" and cant figure out why.
the following is the working script and then the dodgy one.Regardless of what's causing the current error I suspect my code is wrong any ways.Would really appreciate it if someone could point me in the right direction.
PROPERTIES =
{
}
function Initialize()
mtImage = SKIN:GetMeter("Image")
end -- function Initialize
function Update()
Height = mtImage:GetH()
SKIN:Bang("!SetVariable H1 "..Height)
return tostring(Height)
end -- function Update
PROPERTIES =
{
}
function Initialize()
tImage = {}
for i = 1, 2 do
mtImage = SKIN:GetMeter("Image"..i)
end -- function Initialize
function Update()
tHeight = {}
for i = 1, 2 do
tHeight[i] = mtImage:GetH()
SKIN:Bang("!SetVariable H"..i " ".."\""..tHeight[i].."\"")
return tostring(tHeight)
end -- function Update
PROPERTIES =
{
}
function Initialize()
tHeight = {}
for i = 1, 2 do
mtImage = SKIN:GetMeter("Image"..i)
tHeight[i] = mtImage:GetH()
end -- function Initialize
function Update()
SKIN:Bang("!SetVariable H"..i " ".."\""..tHeight[i].."\"")
return tostring(tHeight)
end -- function Update
When in a loop like that, Is assigning all the meters to the same variable (or in this case to the same first cell of a table) over and over. So at the end, mtImage is going to be equal to what ever the LAST image meter is.
You need to:
tImages = {}
for i = 1, 2 do
tImages = SKIN:GetMeter("Image"..i)
end
See what I mean?
Then you have the "pointers" to the meters stored in a table, one per row. Now you can:
for i = 1, 2 do
Height = tImages:GetH()
SKIN:Bang("!SetVariable Meter"..i.."H".." "..Height)
-- sends "!SetVariable Meter1H xx" for the first loop...
First, you need to end your for statements. Second, you're trying to assign multiple meters to the same variable.
function Initialize()
tImage,tHeight = {},{}
for i = 1, 2 do
tImage = SKIN:GetMeter("Image"..i)
end
end -- function Initialize
function Update()
for i = 1, 2 do
tHeight = mtImage:GetH()
SKIN:Bang("!SetVariable H"..i " ".."\""..tHeight.."\"")
end
return tostring(tHeight[1])
end -- function Update
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .
I think smurfie and I are posting at the same time. Based on a quick look, I think we are more or less saying the same thing.
The only real differences are that I don't do quite as much "quoting" in the bang when there is no whitespace in the values, and you don't really need tHeight to be a table. It is fine as a plain variable as you are just reusing it during the loop. No real need to "store" it in a permanent way on each loop. Not in the context of how you are using it anyway.
PROPERTIES =
{
}
function Initialize()
tImages = {}
for i = 1, 2 do
tImages[i] = SKIN:GetMeter("Image"..i)
end -- function Initialize
function Update()
for i = 1, 2 do
Height = tImages[i]:GetH()
SKIN:Bang("!SetVariable H"..[i].." "..Height)
end
return tostring(Height[i])
end -- function Update