In other languages: 中文

Tutorial:Modding FAQ: Difference between revisions

From Official Factorio Wiki
Jump to navigation Jump to search
(spelling fixes)
(removed outdated tips, added some new ones)
 
(23 intermediate revisions by 13 users not shown)
Line 1: Line 1:
== '''Modding FAQ''' ==
{{Languages}}
{{sublinks|Main Page}}
This is a list of common questions asked by new mod makers. Feel free to edit and update with new questions and answers.


Welcome to the modding FAQ. (work in progress)
== Errors ==
Here we have a list of questions that are common to get while writing a mod.
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.
And the fix for the problem (if someone managed to find a fix)
feel free to edit this page and add more Q and A's.


{| style="width: 99%;"
=== "C:\Factorio\mod doesn't match the expected mod_version# (case sensitive!)" ===
|style="width:34%;background: #F9F9F9; border: 1px solid #AAAAAA; vertical-align: top; -moz-border-radius: 5px; -webkit-border-radius: 5px; padding: 7px;"|
<div style="background: #E4F0F7; padding: 5px; margin: 3px; font-weight: bold; text-align: center; color: #033251; font-size: 120%;">
'''Questions / Fix'''</div><div style="padding-left: 1em;">
* Q : my item / entity wont load the sprite I made.
* Fix :
Make sure your path is right : __mod-name__/map-name/2nd-map-name/sprite.png
* Q : my item gives a : unknown key :"items.name.item-x", in game.
* Fix :
make sure you have a "local" map in your mod that contains an "en"(English) file and put an item-name.lua file in ther.
The item-name.lua sould contain :
[item-name]
item-x=Item x
item-y=Item y
* Q : Error while loading prototype "entity-name": No such node (pictures).
* Fix :
Make sure your entity contains the right amount of lines for that type of entity,
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.


|}
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 <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.
 
== 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 <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
 
=== 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? ===
 
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 [http://lua-api.factorio.com/latest/Global.html 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 <code>electric energy interface</code> 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 <code>enabled</code> 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:
 
<pre>
"dependencies": ["? MAIN-DyTech-Machine", "? CORE-DyTech-Core", "bobenemies>=0.13.1", "bobores", "? 5dim_ores"],
</pre>
 
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 [http://lua-api.factorio.com/latest/Data-Lifecycle.html 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.

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