[Done] Help with Code

Place to get help with not working mods / modding interface.
TheSAguy
Smart Inserter
Smart Inserter
Posts: 1456
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

[Done] Help with Code

Post 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,
Last edited by TheSAguy on Mon Mar 18, 2019 8:00 pm, edited 1 time in total.
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3749
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Help with Code

Post 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
TheSAguy
Smart Inserter
Smart Inserter
Posts: 1456
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

Re: Help with Code

Post by TheSAguy »

Thanks!
Post Reply

Return to “Modding help”