1

i can't figure this one out. Maybe you can give it a shot.

return function()
local handle = get.handle
local group1 = handle('group 1') --returns the namelabel of group 1
local group2 = handle('group 2')

for i=1,6
  do
local groupx = group1 -- convert to groupx since i also have a group2 etc.
-- some process with group1 --    
local groupx = string.sub(groupx, 6)
print(groupx) -- number 1
local groupx = groupx +1 
print(groupx) -- number 2.0
local groupx = string.format("%.f",groupx)
fdb(groupx) -- number 2
groupx = string.format('group%s', groupx)
fdb(groupx) -- shows group2
-- some process with group2 --
  end
end

it doesn't seem to work. i can't just loop from group1 to group6 by adding 1 integer at each loop. i found the gsub, but that was mostly done with only text strings, not a variable that changes every time in the loop.

could someone please help me to proper code this. My thanks will be huge.

with kind regards,

Martijn

Doug Currie
  • 40,708
  • 1
  • 95
  • 119

1 Answers1

1

You seem to be confusing variables and strings. Local variables do not, in general, have string names at runtime.

Here are some more direct approaches...

local groups = {handle('group 1'),
                handle('group 2'),
                handle('group 3'),
                handle('group 4'),
                handle('group 5'),
                handle('group 6')}
for i = 1, 6 do
    local groupx = groups[i]
    -- etc.
end

Or

for i = 1, 6 do
    local groupx = handle(string.format('group %d', i))
    -- etc.
end

Or

local groups = {}
for i = 1, 6 do
    groups[i] = handle(string.format('group %d', i))
end
for i = 1, 6 do
    local groupx = groups[i]
    -- etc.
end
Doug Currie
  • 40,708
  • 1
  • 95
  • 119