Page 1 of 1

crafting_categories

Posted: Tue Nov 18, 2014 4:37 pm
by L0771
Hi, i want add a new crafting_categories in the player, i think it is basic, but it not returned an error and it not work

Code: Select all

for _,v in ipairs(data.raw.player) do
	v.crafting_categories[#crafting_categories + 1] = {"cursed-nocraftmachine"}
end

Re: crafting_categories

Posted: Tue Nov 18, 2014 4:56 pm
by rk84
Loop is unnecessary if you want to edit just single player prototype (the one that is used as default for all players) and data.raw's type and name tables are not arrays.

Code: Select all

local player = data.raw.player.player
player.crafting_categories[#player.crafting_categories + 1] = "cursed-nocraftmachine" -- this should result {"crafting","cursed-nocraftmachine"} in player.crafting_categories

Re: crafting_categories

Posted: Tue Nov 18, 2014 5:11 pm
by L0771
Thanks you! it works!

but if a mod edit this player or have some added players?

Re: crafting_categories

Posted: Tue Nov 18, 2014 5:20 pm
by rk84
L0771 wrote:Thanks you! it works!

but if a mod edit this player or have some added players?
There should not be conflict if another mod edits the crafting_categories same way as above or uses table.insert()

For additional player prototypes you could use your code (I fixed 3 things).

Code: Select all

for _,v in pairs(data.raw.player) do
   v.crafting_categories[#v.crafting_categories + 1] = "cursed-nocraftmachine"
end