Re: using util.merge how does it works?
Posted: Mon Sep 16, 2019 11:58 am
Did you mean to ask another question, here?
Did you mean to ask another question, here?
Yeah, can i write all my questions down here or how should i handle this?
Code: Select all
--item.lua
local fireArmor = table.deepcopy(data.raw.armor["heavy-armor"])
fireArmor.name = "fire-armor"
fireArmor.icons= {
{
icon=fireArmor.icon,
tint={r=1,g=0,b=0,a=0.3}
},
}
fireArmor.resistances = {
{
type = "physical",
decrease = 6,
percent = 10
},
{
type = "explosion",
decrease = 10,
percent = 30
},
{
type = "acid",
decrease = 5,
percent = 30
},
{
type = "fire",
decrease = 0,
percent = 100
},
}
local recipe = table.deepcopy(data.raw.recipe["heavy-armor"])
recipe.enabled = true
recipe.name = "fire-armor"
recipe.ingredients = {{"copper-plate",200},{"steel-plate",50}}
recipe.result = "fire-armor"
data:extend{fireArmor,recipe}
Code: Select all
local recipe = table.deepcopy(data.raw.recipe["heavy-armor"])
recipe.enabled = true
recipe.name = "fire-armor"
recipe.ingredients = {{"copper-plate",200},{"steel-plate",50}}
recipe.result = "fire-armor"
I'm not sure which part is the "last part" you mean. In the entity prototype, the "result", which is the item you get when you mine the entity, goes inside the minable table. What you really need to do is look, here: https://wiki.factorio.com/Prototype/Entity
Code: Select all
--item.lua
local fireArmor = table.deepcopy(data.raw.armor["heavy-armor"])
fireArmor.name = "fire-armor"
fireArmor.icons= {
{
icon=fireArmor.icon,
tint={r=1,g=0,b=0,a=0.3}
},
}
fireArmor.resistances = {
{
type = "physical",
decrease = 6,
percent = 10
},
{
type = "explosion",
decrease = 10,
percent = 30
},
{
type = "acid",
decrease = 5,
percent = 30
},
{
type = "fire",
decrease = 0,
percent = 100
},
}
local recipe = table.deepcopy(data.raw.recipe["heavy-armor"])
recipe.enabled = true
recipe.name = "fire-armor"
recipe.ingredients = {{"copper-plate",200},{"steel-plate",50}}
recipe.result = "fire-armor"
data:extend{fireArmor,recipe}
The filenames and directory structure of your mod are entirely up to you and have no influence on the data structure.Palaber1984 wrote: Mon Sep 16, 2019 5:04 pm Edit: and can i put all like tech,item,recipe and entity together using the local deepcopy element? in one lua?
Code: Select all
--prototypes/entity.lua
local sep1 = table.deepcopy(data.raw["electric-pole"]["small-electric-pole"])
sep1.name = "small-electric-pole",
sep1.minable = {mining_time = 0.1, result = "small-electric-pole"},
sep1.max_health = 50,
sep1.maximum_wire_distance = 7.5,
sep1.supply_area_distance = 2.5,
local sep2 = table.deepcopy(data.raw["electric-pole"]["small-electric-pole"])
sep2.name = "small-electric-pole-2",
sep2.minable = {mining_time = 0.1, result = "small-electric-pole-2"},
sep2.max_health = 50,
sep2.maximum_wire_distance = 16,
sep2.supply_area_distance = 1.5,
local mep1 = table.deepcopy(data.raw["electric-pole"]["medium-electric-pole"])
mep1.name = "medium-electric-pole",
mep1.minable = {mining_time = 0.1, result = "medium-electric-pole"},
mep1.max_health = 100,
mep1.maximum_wire_distance = 9,
mep1.supply_area_distance = 3.5,
local mep2 = table.deepcopy(data.raw["electric-pole"]["medium-electric-pole"])
mep2.name = "medium-electric-pole-2",
mep2.minable = {mining_time = 0.1, result = "medium-electric-pole-2"},
mep2.max_health = 100,
mep2.maximum_wire_distance = 14,
mep2.supply_area_distance = 6.5,
local bep1 = table.deepcopy(data.raw["electric-pole"]["big-electric-pole"])
bep1.name = "big-electric-pole",
bep1.minable = {mining_time = 0.1, result = "big-electric-pole"},
bep1.max_health = 250,
bep1.maximum_wire_distance = 30,
bep1.supply_area_distance = 2,
local bep2 = table.deepcopy(data.raw["electric-pole"]["big-electric-pole"])
bep2.name = "big-electric-pole-2",
bep2.minable = {mining_time = 0.1, result = "big-electric-pole-2"},
bep2.max_health = 250,
bep2.maximum_wire_distance = 30,
bep2.supply_area_distance = 4,
local bep3 = table.deepcopy(data.raw["electric-pole"]["big-electric-pole"])
bep3.name = "big-electric-pole-3",
bep3.minable = {mining_time = 1, result = "big-electric-pole-3"},
bep3.max_health = 2000,
bep3.maximum_wire_distance = 64,
bep3.supply_area_distance = 1,
local sub1 = table.deepcopy(data.raw["electric-pole"]["substation"])
sub1.name = "substation",
sub1.minable = {mining_time = 0.1, result = "substation"},
sub1.max_health = 250,
sub1.maximum_wire_distance = 18,
sub1.supply_area_distance = 9,
local sub2 = table.deepcopy(data.raw["electric-pole"]["substation"])
sub2.name = "substation-2",
sub2.minable = {mining_time = 0.1, result = "substation-2"},
sub2.max_health = 250,
sub2.maximum_wire_distance = 58,
sub2.supply_area_distance = 7,
local sub3 = table.deepcopy(data.raw["electric-pole"]["substation"])
sub3.name = "substation-3",
sub3.minable = {mining_time = 0.1, result = "substation-3"},
sub3.max_health = 500,
sub3.maximum_wire_distance = 8,
sub3.supply_area_distance = 64,
data:extend{sep1,sep2,mep1,mep2,bep1,bep2,bep3,sub1,sub2,sub3}
Code: Select all
minable = {mining_time = 0.1, result = "small-electric-pole"},
Code: Select all
local sep1 = table.deepcopy(data.raw["electric-pole"]["small-electric-pole"])
sep1.name = "small-electric-pole"
sep1.minable = {mining_time = 0.1 result = "small-electric-pole"}
sep1.max_health = 50
sep1.maximum_wire_distance = 7.5
sep1.supply_area_distance = 2.5
I think you're having trouble with understanding the difference between creating a table all at once and taking an existing table, then changing individual entries.
Code: Select all
local table =
{
thing1 = "foo",
thing2 = "yo",
thing3 = "bar"
}
Code: Select all
local table2 = util.table.deepcopy(table)
table2.thing2 = "notyo"
Code: Select all
{
thing1 = "foo",
thing2 = "notyo",
thing3 = "bar"
}
Code: Select all
table2.thing3 = table2.thing1
table2.thing1 = "bar"
table2.newthing = "new"
Code: Select all
{
thing1 = "bar",
thing2 = "notyo",
thing3 = "foo",
newthing = "new"
}
Exactly. And congratulations!Palaber1984 wrote: Mon Sep 16, 2019 6:32 pm ah ok, when creating a table then with comma, and when changing a table then without.
BTW, my mod runs now with this short way,
thx, but now my next big thing is comingAdamo wrote: Mon Sep 16, 2019 6:34 pmExactly. And congratulations!Palaber1984 wrote: Mon Sep 16, 2019 6:32 pm ah ok, when creating a table then with comma, and when changing a table then without.
BTW, my mod runs now with this short way,
Uhh, well, that's where the deepcopy function comes from, I think... util.table.deepcopy(). I assume you have access to it just using table.deepcopy() because somewhere along the way, in some data file somewhere, either in another mod or in the base mod, there is a line that says "table = util.table", or something similar. But I don't know for sure.
Deepcopy makes a NEW TABLE that is a COPY of the table you fed to it. So anything you delete in the new table will only be deleted in the new table. To delete an entry in the table you just do something like
Code: Select all
local table2 = util.table.deepcopy(table)
table2.thing2 = nil
Code: Select all
{
thing1 = "foo",
thing3 = "bar"
}
Code: Select all
{
type = "electric-pole",
name = "small-electric-pole",
icon = "__base__/graphics/icons/small-electric-pole.png",
icon_size = 32,
flags = {"placeable-neutral", "player-creation", "fast-replaceable-no-build-while-moving"},
minable = {mining_time = 0.1, result = "small-electric-pole"},
max_health = 50,
corpse = "small-electric-pole-remnants",
collision_box = {{-0.15, -0.15}, {0.15, 0.15}},
selection_box = {{-0.4, -0.4}, {0.4, 0.4}},
drawing_box = {{-0.5, -2.6}, {0.5, 0.5}},
maximum_wire_distance = 7.5,
supply_area_distance = 2.5,
vehicle_impact_sound = { filename = "__base__/sound/car-wood-impact.ogg", volume = 1.0 },
track_coverage_during_build_by_moving = true,
fast_replaceable_group = "electric-pole",
pictures =
{
layers =
{
{
filename = "__base__/graphics/entity/small-electric-pole/small-electric-pole.png",
priority = "extra-high",
width = 36,
height = 108,
direction_count = 4,
shift = util.by_pixel(2, -42),
hr_version =
{
filename = "__base__/graphics/entity/small-electric-pole/hr-small-electric-pole.png",
priority = "extra-high",
width = 72,
height = 220,
direction_count = 4,
shift = util.by_pixel(1.5, -42.5),
scale = 0.5
}
},
{
filename = "__base__/graphics/entity/small-electric-pole/small-electric-pole-shadow.png",
priority = "extra-high",
width = 130,
height = 28,
direction_count = 4,
shift = util.by_pixel(50, 2),
draw_as_shadow = true,
hr_version =
{
filename = "__base__/graphics/entity/small-electric-pole/hr-small-electric-pole-shadow.png",
priority = "extra-high",
width = 256,
height = 52,
direction_count = 4,
shift = util.by_pixel(51, 3),
draw_as_shadow = true,
scale = 0.5
}
}
}
},
connection_points =
{
{
shadow =
{
copper = util.by_pixel(98.5, 2.5),
red = util.by_pixel(111.0, 4.5),
green = util.by_pixel(85.5, 4.0)
},
wire =
{
copper = util.by_pixel(0.0, -82.5),
red = util.by_pixel(13.0, -81.0),
green = util.by_pixel(-12.5, -81.0)
}
},
{
shadow =
{
copper = util.by_pixel(99.5, 4.0),
red = util.by_pixel(110.0, 9.0),
green = util.by_pixel(92.5, -4.0)
},
wire =
{
copper = util.by_pixel(1.5, -81.0),
red = util.by_pixel(12.0, -76.0),
green = util.by_pixel(-6.0, -89.5)
}
},
{
shadow =
{
copper = util.by_pixel(100.5, 5.5),
red = util.by_pixel(102.5, 14.5),
green = util.by_pixel(103.5, -3.5)
},
wire =
{
copper = util.by_pixel(2.5, -79.5),
red = util.by_pixel(4.0, -71.0),
green = util.by_pixel(5.0, -89.5)
}
},
{
shadow =
{
copper = util.by_pixel(98.5, -1.5),
red = util.by_pixel(88.0, 3.5),
green = util.by_pixel(106.0, -9.0)
},
wire =
{
copper = util.by_pixel(0.5, -86.5),
red = util.by_pixel(-10.5, -81.5),
green = util.by_pixel(8.0, -93.5)
}
}
},
radius_visualisation_picture =
{
filename = "__base__/graphics/entity/small-electric-pole/electric-pole-radius-visualization.png",
width = 12,
height = 12,
priority = "extra-high-no-scale"
}
},
Code: Select all
direction_count = 4,
Code: Select all
{
shadow =
{
copper = util.by_pixel(99.5, 4.0),
red = util.by_pixel(110.0, 9.0),
green = util.by_pixel(92.5, -4.0)
},
wire =
{
copper = util.by_pixel(1.5, -81.0),
red = util.by_pixel(12.0, -76.0),
green = util.by_pixel(-6.0, -89.5)
}
},
{
shadow =
{
copper = util.by_pixel(100.5, 5.5),
red = util.by_pixel(102.5, 14.5),
green = util.by_pixel(103.5, -3.5)
},
wire =
{
copper = util.by_pixel(2.5, -79.5),
red = util.by_pixel(4.0, -71.0),
green = util.by_pixel(5.0, -89.5)
}
},
{
shadow =
{
copper = util.by_pixel(98.5, -1.5),
red = util.by_pixel(88.0, 3.5),
green = util.by_pixel(106.0, -9.0)
},
wire =
{
copper = util.by_pixel(0.5, -86.5),
red = util.by_pixel(-10.5, -81.5),
green = util.by_pixel(8.0, -93.5)
}
}
Code: Select all
sep1.pictures = {layers = {{direction_count = 1, {direction_count = 1}}, direction_count = 1, {direction_count = 1}}}
Code: Select all
pictures =
{
layers =
{
{
filename = "__base__/graphics/entity/small-electric-pole/small-electric-pole.png",
priority = "extra-high",
width = 36,
height = 108,
direction_count = 4,
shift = util.by_pixel(2, -42),
hr_version =
{
filename = "__base__/graphics/entity/small-electric-pole/hr-small-electric-pole.png",
priority = "extra-high",
width = 72,
height = 220,
direction_count = 4,
shift = util.by_pixel(1.5, -42.5),
scale = 0.5
}
},
{
filename = "__base__/graphics/entity/small-electric-pole/small-electric-pole-shadow.png",
priority = "extra-high",
width = 130,
height = 28,
direction_count = 4,
shift = util.by_pixel(50, 2),
draw_as_shadow = true,
hr_version =
{
filename = "__base__/graphics/entity/small-electric-pole/hr-small-electric-pole-shadow.png",
priority = "extra-high",
width = 256,
height = 52,
direction_count = 4,
shift = util.by_pixel(51, 3),
draw_as_shadow = true,
scale = 0.5
}
}
}
},
You're overwriting the whole table.Palaber1984 wrote: Tue Sep 17, 2019 12:25 pmCode: Select all
sep1.pictures = {layers = {{direction_count = 1, {direction_count = 1}}, direction_count = 1, {direction_count = 1}}}