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.

Why do I get the error "C:\Factorio\mod doesn't match the expected mod_version# (case sensitive!)" error?

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".

My item / entity wont load the sprite I made.

Make sure your path is right : __mod-name__/map-name/2nd-map-name/sprite.png. Pay attention to case, the following file is not the same as previous: __Mod-name__/Map-name/2nd-map-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

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

What does ('=' character not found in line) mean?

If you get the error message '=' character not found in line , chances are you created a new document as something other than a .txt file, adding in format text to the document that is causing this error. Copy the contents of your .cfg file and make a new .txt file, rename it to .cfg, and paste your configuration into it. This is due to Windows' odd behavior with file types.

Error while loading prototype "entity-name": No such node (pictures).

Make sure your entity contains the right amount of lines for that type of for example a chest needs 1 picture for the entity to work but a wall needs 20. Look in the factorio base/prototypes/entity/entity.lua. And you can see that different entities need different amounts of pictures.

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. 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 the game to crash if they are not met or ill-defined. Dependencies also cannot be circular, if another mod requires yours, you cannot require it.

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.

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.

What is the "attempt to index a nil value" error?

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. If you look around the error box, you should see the file and line where the error occurred, go there and try to figure out why the specific thing it's trying to access doesn't exist. This happens most often with accessing Factorio's 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.