Page 1 of 1
Problem with deepcopy
Posted: Sat Sep 26, 2020 3:04 am
by ShadowScaleFTL
Code: Select all
require ("util")
local usplit = {}
usplit = util.table.deepcopy(data.raw["splitter"]["hacked-splitter"])
usplit.name = "basic-hacked-splitter",
usplit.minable = {mining_time = 1, result = "basic-hacked-splitter"}
data:extend({usplit})
Im trying to create entity for my splitter with deepcopy. But got error "unexpected symbol near '=' at line
Code: Select all
usplit.minable = {mining_time = 1, result = "basic-hacked-splitter"}
if i just delete this line all works, exept my splitter mines another item, so i need to change minable property somehow. But all things i tryied just wont work.
Re: Problem with deepcopy
Posted: Sat Sep 26, 2020 3:08 am
by DaveMcW
The previous line has an extra comma.
Re: Problem with deepcopy
Posted: Sat Sep 26, 2020 3:21 am
by ShadowScaleFTL
DaveMcW wrote: Sat Sep 26, 2020 3:08 am
The previous line has an extra comma.
now it gives me another error
"attempt to index local 'usplit' (a nil value)" at prev. line
current code
Code: Select all
require ("util")
local usplit = {}
usplit = util.table.deepcopy(data.raw["splitter"]["hacked-splitter"])
usplit.name = "basic-hacked-splitter"
usplit.minable = {mining_time = 1, result = "basic-hacked-splitter"}
data:extend({usplit})
Re: Problem with deepcopy
Posted: Sat Sep 26, 2020 3:37 am
by DaveMcW
Are you sure data.raw["splitter"]["hacked-splitter"] already exists? Did you mean to copy data.raw["splitter"]["splitter"]?
Re: Problem with deepcopy
Posted: Sat Sep 26, 2020 3:59 am
by ShadowScaleFTL
DaveMcW wrote: Sat Sep 26, 2020 3:37 am
Are you sure data.raw["splitter"]["hacked-splitter"] already exists? Did you mean to copy data.raw["splitter"]["splitter"]?
hacked-splitter is from another mod. And its work. I tryied move my code to data-updates or data-final-fixes but nothing has changed.
Here is code from those mode
vanila.lua
Code: Select all
local hacked = require "hacked"
-- Entity definitions
splitters = {"splitter", "fast-splitter", "express-splitter"}
for i, name in ipairs (splitters) do
hacked.make_hacked_entity (name)
end
hacked.lua
Code: Select all
require "util"
local hacked = {}
function hacked.make_hacked_entity (name)
if data.raw["splitter"][name] ~= nil then
local hacked = "hacked-"..name
local template = util.table.deepcopy (data.raw["splitter"][name])
template.name = hacked
template.minable.result = hacked
template.structure.north = make_anim (template.structure.north, "north")
template.structure.east = make_anim (template.structure.east, "east")
template.structure.south = make_anim (template.structure.south, "south")
template.structure.west = make_anim (template.structure.west, "west")
data:extend({template})
end
end
return hacked
Re: Problem with deepcopy
Posted: Sat Sep 26, 2020 4:54 am
by DaveMcW
hacked-splitters uses data-updates.lua.
Therefore you must use data-updates.lua with a info.json depenency on hacked-splitters.
Code: Select all
"dependencies": ["base", "hacked-splitters"],
Re: Problem with deepcopy
Posted: Sat Sep 26, 2020 5:43 am
by ShadowScaleFTL
DaveMcW wrote: Sat Sep 26, 2020 4:54 am
hacked-splitters uses data-updates.lua.
Therefore you must use data-updates.lua with a info.json depenency on hacked-splitters.
Code: Select all
"dependencies": ["base", "hacked-splitters"],
its work! Seems i tryed data-updates before with my prev. bug and thought its not a solution but it was!