First mod help

Place to get help with not working mods / modding interface.
Post Reply
Gridbug
Manual Inserter
Manual Inserter
Posts: 2
Joined: Sat Mar 09, 2024 12:45 pm
Contact:

First mod help

Post by Gridbug »

Hello,

I've just started out trying to make a Factorio mod and already beating my head against the wall :lol:

Im trying to create a new item, in data.lua I have:

local myItem = table.deepcopy(data.raw["item"]["iron-plate"])

myItem.name = "my-item"

local recipe = {
type = "recipe",
name = "my-item",
enabled = true,
energy_required = 1,
ingredients = {{"iron-plate", 100}},
result = "my-item"
}
data:extend{myItem, recipe}

This works fine as long as the thing in the copy field is an item like iron plate, but as soon as I try anything else like data.raw["container"]["wooden-chest"] or data.raw["transport-belt"]["transport-belt"], I get the error:

Failed to load mods: Error in assignID: item with name 'my-item' does not exist.
Source: my-item (recipe).

Does anyone know what I'm doing wrong?

Qon
Smart Inserter
Smart Inserter
Posts: 2118
Joined: Thu Mar 17, 2016 6:27 am
Contact:

Re: First mod help

Post by Qon »

Gridbug wrote:
Sat Mar 09, 2024 12:59 pm
This works fine as long as the thing in the copy field is an item like iron plate, but as soon as I try anything else like data.raw["container"]["wooden-chest"] or data.raw["transport-belt"]["transport-belt"], I get the error:

Failed to load mods: Error in assignID: item with name 'my-item' does not exist.
Source: my-item (recipe).
If you don't create the item "my-item", it won't exist. data.raw["transport-belt"]["transport-belt"] is an entity of type "transport-belt".
As the docs say:
https://lua-api.factorio.com/latest/prototypes/TransportBeltPrototype.html wrote: Inherits from TransportBeltConnectablePrototype « EntityWithOwnerPrototype « EntityWithHealthPrototype « EntityPrototype « PrototypeBase
items are things you have in inventories, entities are placed on the ground. You can't have a recipe that produces an entity.
You could copy the item "transport-belt" from from data.raw["item"]["transport-belt"] if you want the icon and stack size etc similar to it.

Items and entities are connected with "place_result" (item in hand, place on ground) in the item prototype and with "minable" (what you get when you mine the entity) in the entity prototype. This isn't automatic and you aren't forced to have a 2-cycle of item->entity->same item again, you could get anything from mining the entity and place anything when building with the item. like item transport-belt placed -> builds assembler -> mined iron-plate -> iron plate when built places a laser turret etc. And I think you can get 3 steel plate and 5 rocket silo items when mining something as well...

Gridbug
Manual Inserter
Manual Inserter
Posts: 2
Joined: Sat Mar 09, 2024 12:45 pm
Contact:

Re: First mod help

Post by Gridbug »

That works! Thank you so much :)

Post Reply

Return to “Modding help”