In other languages: 简体中文

Tutorial:Modding FAQ

From Official Factorio Wiki
Jump to navigation Jump to search

This is a list of common questions asked by new mod makers. Feel free to edit and update with new questions and answers.

Errors

General note: Errors give you either a line info or at least a reference as to where the error occurred. If a line is specified, then the odds are high that the mistake actually happened on one of the previous lines. Try to check for common errors like missing a comma while defining an array or writing data.extend instead of data:extend beforehand.

"C:\Factorio\mod doesn't match the expected mod_version# (case sensitive!)"

The folder name of your mod must include the version number, and name of the mod separated by an underscore. So if your mod is titled "myMod" version 0.0.1, in order for Factorio to read it, the folder must be titled "myMod_0.0.1".

"attempt to index a nil value"

This is a Lua error that means the mod is trying to access a value that doesn't exist. Similar to a Null Pointer in other programming languages, you're trying to access something that doesn't exist. This happens most often with accessing Factorios custom Lua tables, and trying to access a var that doesn't exist within that table. This also happens with developers experienced in other programming languages that forget that Lua tables are indexed from 1, not 0. Table[0] doesn't exist by default in Lua.

Failed to load mods: Error while loading prototype "prototype-name" (prototype-type): Key "property-name" not found in property tree at ROOT.prototype-type.prototype-name

Your prototype with the name prototype-name and type prototype-type is missing the property-name property. You need to add it to make it possible for the game to load.

Problems

My item / entity wont load the sprite I made.

Make sure your path is right : __mod-name__/folder-name/2nd-folder-name/sprite.png. Pay attention to case, the following file is not the same as previous: __Mod-name__/Folder-name/2nd-folder-name/sprite.PNG. Also note that Factorio is only capable of loading png files for icons and entity textures.

The name of my item is displayed as "Unknown key: item-name.yourname"

Make sure you have valid locale mappings. Create a "locale" directory with an "en" sub-directory and create a "item-name.cfg" file. It should contains something like:

 [item-name]
 itemx=Item X
 itemy=Item Y

Make sure there are no spaces before or after the =. Do the same for your entities, but put them in an [entity-name] section/file. For each [xxx-name] section you should preferably also add a section [xxx-description], which will then display as description when you hover over the corresponding item/entity/technology/mod-setting

I'm trying to change the attributes of a vanilla entity, but it's not working!

If there are other mods installed in your dev environment, it's possible that their changes are overwriting yours. (A good find if this is true, because this is an incompatibility!) To fix, you need to add the mod that's doing it (up to you to find) as an optional dependency, so it gets loaded first. This ensures that your changes overwrite theirs.

Be careful though, if the mod in question is expecting it's changes to stick, you could break the mod. If so, this means that your mod is permanently incompatible with that mod, so you should declare that fact in your mod's description and in the dependencies by listing the mod with a ! in front:

"dependencies": ["base", "? optional-dependency >=0.13.1", "! incompatible-mod"]

My mod does not show up in game

Your info.json has a problem/doesn't exist. Make sure you have a info.json file in the root folder of your mod, that it has the right file extension (.json), and the right factorio_version. The json also does not allow trailing commas in lists, the game will print that error to the log file and refuse to load the mod until you fix it. Other errors such as wrong format for dependenciescan also be found in the log file.

Other

How do I store information with an entity, like integers or booleans?

Factorio's API ensures that modders use the proper way to do things, to reduce the possible instability arising from modders doing strange workarounds. The proper way to store data with an entity is to use a table in the global table that contains the entity and information. If you then need to access it, you can write code to get the value out of the table that corresponds to the entity. It isn't possible to store data on an entity in any other way, either in the control stage or data stage. Some entity types do have space for variables, as of 0.15.

How do I make an entity store/consume energy even if it wasn't made to?

Use of the electric energy interface allows for arbitrary electricity handling. You will need to spawn this entity on top of yours, and clean it up when your entity is destroyed. Scripting is also necessary to gate the entity's functions behind energy requirements.

How can I disable a recipe with scripting?

Simple, just set it's enabled tag to false. An item's recipe can be obtained through its prototype.

How do I declare a dependency of my mod?

This is done in the info.json file of your mod. Under the dependency field, simply place the internal name (Not the pretty title!) of the mod you want to declare as a dependency. It is a json table, so multiple can be defined. If you want to declare it as an optional dependency, then put a question mark and space before the name. To define a minimum version, simply put a logic operator, such as >=, and a version. As an example:

"dependencies": ["? MAIN-DyTech-Machine", "? CORE-DyTech-Core", "bobenemies>=0.13.1", "bobores", "? 5dim_ores"],

Be careful with required dependencies, as they will cause your mod to be disabled if they are unmet or ill-defined. Dependencies also cannot be circular, if another mod requires yours, you cannot require it; Somebody has to load first.

How are mods loaded in Factorio?

See this page by the developers, it sums up the process very well.

How do I submit my mod to the mod portal?

Login with your Factorio.com account, and click the submit mod button in the top right corner. Provide the mod as a zip file, and write a description/upload some pics. The title, version, etc is all pulled from the zip. The mod name may not contain spaces.