In other languages: 中文

Tutorial:Modding FAQ

From Official Factorio Wiki
Revision as of 21:44, 26 July 2017 by Xerus (talk | contribs) (new section "Poblems")
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. Especially if you want to release your mod: Add safety checks against these kind of errors and preferably redirect them to the console via print(...) so users can conveniently report them to you without being interrupted in their game!

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.

'=' character not found in line

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 behaviour with file types.

Problems

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

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.

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

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.