Page 1 of 1

[SOLVED][HELP] data.raw Difficulty error

Posted: Wed Jan 25, 2023 3:13 pm
by dtoxic
Ok so i tried to edit some stuff in another mod but i get a error because the difficulty (normal,expensive i think) is not defined in my code but neither is in the mod that i try to edit i think, any way here is the code and the error but i don't know where to define the difficulty

Code: Select all

data.raw.technology["power-cells"].prerequisites = {"electric-machinery"}
data.raw.technology["power-cells"].unit.ingredients = {count = 50, ingredients = "early-science-pack", 1, time = 10}

Code: Select all

Error
Failed to load mods: Error while loading technology prototype "power-cells" (technology): Difficulty normal: Value must be a dictionary in property tree at ROOT.technology.power-cells.unit.ingredients.1

Re: [HELP] data.raw Difficulty error

Posted: Wed Jan 25, 2023 5:03 pm
by Hornwitser
This does not have anything to do with difficulty other than the place you put the ingredients to apply for normal difficulty. The documentation for ingredients state that it is a table of IngredientsPrototype. The error is saying it expected to find a table inside data.raw.technology["power-cells"].unit.ingredients[1], but it found the digit 1 instead. If you are confused you can use a log statement like

Code: Select all

log(serpent.block(data.raw.technology["power-cells"]))
to print out what the prototype looks like after you modified it to factorio-current.log.

Re: [HELP] data.raw Difficulty error

Posted: Wed Jan 25, 2023 5:09 pm
by DarkShadow44
You should look to other mods or the docs (not sure why I can't find technology.unit in the docs though).
Try

Code: Select all

data.raw.technology["automation"].unit = {count = 2, ingredients = {{"automation-science-pack", 4}}, time = 12}

Re: [HELP] data.raw Difficulty error

Posted: Wed Jan 25, 2023 5:10 pm
by dtoxic
ok the "1" is for that science pack needed....so should i write "amount = 1" ?

here is the original code from the mod i am trying to change the automation science pack to a different science pack from a different mod and count and time
so i left the "1" there made sense to me...but then again me and my coding skill = -1

Code: Select all

data:extend({
    {
        type = "technology",
        name = "power-cells",
        icon = "__power-cells__/graphics/technology/capacitive-cell.png",
        icon_size = 256,
        effects = {
            {type = "unlock-recipe", recipe = "capacitive-power-cell"},
            {type = "unlock-recipe", recipe = "cell-charger"},
            {type = "unlock-recipe", recipe = "basic-power-station"}
        },
        prerequisites = nil,
        unit = {
            count = 30,
            ingredients = {{"automation-science-pack", 1}},
            time = 15
        }
        -- order = "c-e-b",
    }
})

Re: [HELP] data.raw Difficulty error

Posted: Wed Jan 25, 2023 5:14 pm
by DarkShadow44
Ah, prototype data is in the wiki: https://wiki.factorio.com/Prototype/Technology#unit
You can just follow that to get exactly what you need.
ok the "1" is for that science pack needed....so should i write "amount = 1" ?
Why don't you just test it? Copy my code and see what it does ;)

Wiki and "trial and error" are your friends, so are other open source mods.

Re: [HELP] data.raw Difficulty error

Posted: Wed Jan 25, 2023 5:16 pm
by dtoxic
DarkShadow44 wrote:
Wed Jan 25, 2023 5:09 pm
You should look to other mods or the docs (not sure why I can't find technology.unit in the docs though).
Try

Code: Select all

data.raw.technology["automation"].unit = {count = 2, ingredients = {{"automation-science-pack", 4}}, time = 12}
Yeap this one works,thank you very much!!!

so basically i should have left out ".ingredients" after the "unit" part...and also one more pair of big brackets in the ingredients = part

Re: [HELP] data.raw Difficulty error

Posted: Wed Jan 25, 2023 5:22 pm
by DarkShadow44
Basically. the structure is this:

Code: Select all

unit -> dictionary
    count -> int
    time -> double
    ingredients -> array
    	ingredient1 -> array of name, count
    	...
As noted, the structure is laid out on the wiki.

Re: [SOLVED][HELP] data.raw Difficulty error

Posted: Wed Jan 25, 2023 5:27 pm
by dtoxic
Thank you....will do some more trial and error and try figure it out more things,totally new to modding except some basic things

Re: [SOLVED][HELP] data.raw Difficulty error

Posted: Wed Jan 25, 2023 5:32 pm
by dtoxic
One more question,should i be using data-updates or data-final-fixes for these shenanigans i am trying to do...i am using final fixes because i want them to run after all mods.

Re: [SOLVED][HELP] data.raw Difficulty error

Posted: Wed Jan 25, 2023 5:37 pm
by DarkShadow44
IMHO, I'd do it as soon as you can, just in case someone wants to alter your mod later :)
With a dependency, even data.lua should work, but I'd use updates.

Re: [SOLVED][HELP] data.raw Difficulty error

Posted: Wed Jan 25, 2023 5:41 pm
by dtoxic
yeah i added dependencies in the json file...so data-updates it is,it works as is now but will try it out..thx man for all the help i appreciate it!