Problem with deepcopy

Place to get help with not working mods / modding interface.
User avatar
ShadowScaleFTL
Inserter
Inserter
Posts: 25
Joined: Mon Jan 23, 2017 3:30 pm
Contact:

Problem with deepcopy

Post 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.
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3715
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Problem with deepcopy

Post by DaveMcW »

The previous line has an extra comma.
User avatar
ShadowScaleFTL
Inserter
Inserter
Posts: 25
Joined: Mon Jan 23, 2017 3:30 pm
Contact:

Re: Problem with deepcopy

Post 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})   
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3715
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Problem with deepcopy

Post by DaveMcW »

Are you sure data.raw["splitter"]["hacked-splitter"] already exists? Did you mean to copy data.raw["splitter"]["splitter"]?
User avatar
ShadowScaleFTL
Inserter
Inserter
Posts: 25
Joined: Mon Jan 23, 2017 3:30 pm
Contact:

Re: Problem with deepcopy

Post 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
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3715
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Problem with deepcopy

Post 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"],
User avatar
ShadowScaleFTL
Inserter
Inserter
Posts: 25
Joined: Mon Jan 23, 2017 3:30 pm
Contact:

Re: Problem with deepcopy

Post 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!
Post Reply

Return to “Modding help”