Page 1 of 1

[Done] Help with Code

Posted: Tue Mar 12, 2019 7:47 pm
by TheSAguy
Hi,

I'l looking to create some code that will create a list of dynamic names, based on the available damage types.
For each type, create a set of 1-10 values.

Let's say there are 3 damage types: Physical, Laser and Poison, then the names would range from:
Physical-01-Laser-01-Poison-01
...
Physical-01-Laser-01-Poison-10
...
Physical-01-Laser-10-Poison-10
...
...
Physical-10-Laser-10-Poison-10

Should be a 1,000 combinations.
10 x 10 x 10

So my below code only does it per damage type, now how do I combine the different types?

Code: Select all

for k, v in pairs(data.raw["damage-type"]) do

	for i = 1, 10 do
	local u_name = v.name.."-"..i

	end
	
end
Thanks,

Re: Help with Code

Posted: Tue Mar 12, 2019 9:32 pm
by DaveMcW

Code: Select all

function eat_more_memory(input, damage)
  local output = {}
  for k, v in pairs(input) do
    for i = 1, 10 do
      local u_name = v .. "-" .. damage .. "-" .. string.format("%.2d", i)
      table.insert(output, u_name)
    end
  end
  return output
end

local list = {""}
for k, v in pairs(data.raw["damage-type"]) do
  list = eat_more_memory(list, v.name)
end

Re: Help with Code

Posted: Wed Mar 13, 2019 4:55 pm
by TheSAguy
Thanks!