In other languages: 简体中文

Tutorial:Modding FAQ: Difference between revisions

From Official Factorio Wiki
Jump to navigation Jump to search
(removed outdated tips, added some new ones)
(3 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Languages}}
{{Languages}}
This is a list of common questions asked by new mod makers. Feel free to edit and update with new questions and answers.
This is a list of common questions asked by new mod makers. Feel free to edit and update with new questions and answers.


Line 14: Line 13:
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 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.
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 ===
=== 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 ===


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.
Your prototype with the name <code>prototype-name</code> and type <code>prototype-type</code> is missing the <code>property-name</code> property. You need to add it to make it possible for the game to load.


== Other ==
== Problems ==


=== My item / entity wont load the sprite I made. ===
=== 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.
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" ===
=== The name of my item is displayed as "Unknown key: item-name.yourname" ===
Line 37: Line 31:
   itemy=Item Y
   itemy=Item Y


Do the same for your entities, but put them in an ''[entity-name]'' section/file.
Make sure there are no spaces before or after the <code>=</code>. 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
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 <code>!</code> in front:
<pre>
"dependencies": ["base", "? optional-dependency >=0.13.1", "! incompatible-mod"]
</pre>
=== 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? ===
=== How do I store information with an entity, like integers or booleans? ===
Line 54: Line 64:
=== How do I declare a dependency of my mod? ===
=== 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:
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:


<pre>
<pre>
Line 60: Line 70:
</pre>
</pre>


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.
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.
 
=== 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? ===
=== How are mods loaded in Factorio? ===
Line 74: Line 78:
=== How do I submit my mod to the mod portal? ===
=== 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.
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.

Revision as of 09:07, 29 May 2018

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.