[Guide] Modding and Scripting changes in 0.3.0
[Guide] Modding and Scripting changes in 0.3.0
Modding
There is an introduction into the modding in 0.3.0 at https://forums.factorio.com/wiki/inde ... g_overview. Basically we redone a lot of things to make mods more self-sustained and stackable. The pre 0.3.0 mods are not compatible with the >= 0.3.0 release! Also changing the mods to match the 0.3.0 specs is not that bad (we have migrated all the data in the game to mee the new specs).
Scripting
* The event registering mechanism has been changed in the 0.3.0 and it is not compatible with the old mechanism. You can read the details at the https://forums.factorio.com/wiki/index.php/Lua/Events
* We have introduced a new mechanism for communications between multiple scripts from different mods. This is called Script interfaces and you can read more about it on the wiki: https://forums.factorio.com/wiki/inde ... interfaces
There is an introduction into the modding in 0.3.0 at https://forums.factorio.com/wiki/inde ... g_overview. Basically we redone a lot of things to make mods more self-sustained and stackable. The pre 0.3.0 mods are not compatible with the >= 0.3.0 release! Also changing the mods to match the 0.3.0 specs is not that bad (we have migrated all the data in the game to mee the new specs).
Scripting
* The event registering mechanism has been changed in the 0.3.0 and it is not compatible with the old mechanism. You can read the details at the https://forums.factorio.com/wiki/index.php/Lua/Events
* We have introduced a new mechanism for communications between multiple scripts from different mods. This is called Script interfaces and you can read more about it on the wiki: https://forums.factorio.com/wiki/inde ... interfaces
Re: [Guide] Modding in 0.3.0 introduction
Awesome!!!
I thought you were going to add something like NBT in minecraft, to be able to change the data of some specific machines, not all the machines in the game, that would be even moar awzum.
Hope to see more lua documentation im so excited.
I thought you were going to add something like NBT in minecraft, to be able to change the data of some specific machines, not all the machines in the game, that would be even moar awzum.
Hope to see more lua documentation im so excited.
Re: [Guide] Modding in 0.3.0 introduction
Im ficolas from the future and I have a message.
Its day 269 and im still updating the mod.
There is only a can of water, and there is no food left, I think I will die without updating it...
There are so many ":" to change...
Its day 269 and im still updating the mod.
There is only a can of water, and there is no food left, I think I will die without updating it...
There are so many ":" to change...
Re: [Guide] Modding in 0.3.0 introduction
This is the script I have used to migrate the JSON files from base to Lua.
It doesn't change the dashes to underscores on the left sides.
Code: Select all
-- Migration of the json prototype-definition files into lua data files
-- Requires lua packages serpent and luajson to be on the package.path
-- Note: use luarocks for easy lua package installation
--
-- Usage:
-- lua migratejsons.lua json-paths
-- json-paths is a list of paths to json data files to be migrated
local serpent = require("serpent")
local json = require("json")
function loadpaths(source)
-- first argument should be a file with paths to migrate
local lines = {}
for line in io.lines(source) do
lines[#lines + 1] = line
end
return lines
end
function migrateone(path)
local luadata = json.decode(io.open(path, "r"):read("*all"))
local output = io.open(path:gsub(".json$", ".lua"), "w")
local dump = serpent.block(luadata, {comment=false})
output:write("data:extend(\n" .. dump .. "\n)\n")
end
-- main
lines = loadpaths(arg[1])
for _, line in ipairs(lines) do
migrateone(line)
end
Re: [Guide] Modding in 0.3.0 introduction
thanx, but I alredy did something, and I think I broke something, but I dont know what, can you help?
http://rapidshare.com/files/1129952588/f-mod.rar
http://rapidshare.com/files/1129952588/f-mod.rar
Re: [Guide] Modding in 0.3.0 introduction
What exactly do you mean ?ficolas wrote: thanx, but I alredy did something, and I think I broke something, but I dont know what, can you help?
http://rapidshare.com/files/1129952588/f-mod.rar
I did a very quick check and the mod is not loaded properly. The name of the mod in the info.json file must be the same as the name of the directory. I will add some error reporting for that. If you change the name in the info.json file then there are some more errors to cope with.
Also there have been some scripting changes - I will write an update about those on the wiki soon.
Re: [Guide] Modding in 0.3.0 introduction
error reporting doesnt work fine in this case:
it asks for a "}" more, to close the one at line 3, but there is 1 "{" and 1 "}"... what is the problem there?
Also I cant see the error here:
line 6, expected } to close { at line 2 near =
Code: Select all
data.raw.entity["creeper"].loot=
{
item = "small-alien-artifact",
probability = 1,
count-min= 1,
count-max= 5
}
Also I cant see the error here:
Code: Select all
data:extend({
{
type= "container",
name= "underground-mining-drill",
flags= {"placeable-neutral", "player-creation"},
collision-box= {{-1.4, -1.4}, {1.4, 1.4}},
selection-box= {{-1.5, -1.5}, {1.5, 1.5}},
minable= { mining-time= 1, result= "underground-mining-drill" },
"max-health= 200,
"inventory-size= 4,
"picture=
{
filename= "__f-mod__/resources/entity/underground-mining-drill/underground-mining-drill.png",
width= 96,
height= 96,
priority= "extra-high"
}
},
{
type= "assembling-machine",
name= "alien-assembly-machine",
flags= {"placeable-neutral", "player-creation"},
collision-box= {{-1.4, -1.4}, {1.4, 1.4}},
selection-box= {{-1.5, -1.5}, {1.5, 1.5}},
minable= { hardness= 0.2, mining-time= 0.5, result= "alien-assembly-machine" },
crafting-categories= { "alien-crafting" },
max-health= 150,
drawing-position= {0.7, 0.12},
ingredient-count= 20,
energy-usage-per-tick= 2.5,
effectivity= 1.5,
energy-source=
{
type= "electric",
input-priority= "secondary"
},
animation=
{
filename= "__f-mod__/resources/entity/assembling-machine-2/assembling-machine-2.png",
priority= "medium",
frame-width= 141,
frame-height= 120,
line-length= 6,
frame-count= 32
}
},
{
type= "container",
name= "underground-scanner",
flags= {"placeable-neutral", "player-creation"},
collision-box= {{-1.4, -1.4}, {1.4, 1.4}},
selection-box= {{-1.5, -1.5}, {1.5, 1.5}},
minable= { mining-time= 1, result= "underground-scanner" },
max-health= 200,
inventory-size= 1,
picture=
{
filename= "__f-mod__/resources/entity/underground-mining-drill/underground-scanner.png",
width= 96,
height= 96,
priority= "extra-high"
}
},
{
type= "player-port",
name= "Spawn",
flags= {"placeable-neutral", "player-creation"},
collision-box= {{-0.9, -0.9}, {0.9, 0.9}},
selection-box= {{-1, -1}, {1, 1}},
minable= { mining-time= 1, "result= "Spawn" },
max-health= 50,
animation=
{
filename= "__f-mod__/resources/entity/Spawn/file.png",
frame-width= 64,
frame-height= 64,
line-length= 6,
frame-count= 31,
priority= "high"
}
}
}
)
Re: [Guide] Modding in 0.3.0 introduction
This is how the definition should look like:
There were 2 errors:
* There path to the loot element didn't make sense so it came out as nil indexing
* The dash ("-") can't be used in identifiers in Lua becose it is parsed as a minus sign. Therefore we have changed all the left hand identifiers
in the from the JSON definitions to use the underscores instead.
Code: Select all
data.raw["unit-spawner"]["creeper-spawner"].loot =
{
{
item = "small-alien-artifact",
probability = 1,
count_min= 1,
count_max= 5
}
}
* There path to the loot element didn't make sense so it came out as nil indexing
* The dash ("-") can't be used in identifiers in Lua becose it is parsed as a minus sign. Therefore we have changed all the left hand identifiers
in the from the JSON definitions to use the underscores instead.
Re: [Guide] Modding in 0.3.0 introduction
I didnt want to change the creeper spawner´s loot, I wanted to change creeper's loot.slpwnd wrote:This is how the definition should look like:
Code: Select all
data.raw["unit-spawner"]["creeper-spawner"].loot = { { item = "small-alien-artifact", probability = 1, count_min= 1, count_max= 5 } }
Omg moar work xDslpwnd wrote:* The dash ("-") can't be used in identifiers in Lua becose it is parsed as a minus sign. Therefore we have changed all the left hand identifiers
in the from the JSON definitions to use the underscores instead
Last edited by ficolas on Sat Mar 30, 2013 10:33 pm, edited 1 time in total.
Re: [Guide] Modding in 0.3.0 introduction
just imagine how much they've put into this update:ficolas wrote:Omg moar work xD
They had to figure out the best way to set it up
then they had to convert the base 'mod'
and test it to make sure everything worked
Then they have to write up a wiki for everything
AND THEN they have to put up with everyone who gets confused by the update
<I'm really not active any more so these may not be up to date>
~FreeER=Factorio Modding
- Factorio Wiki
- My Factorio Modding Guide
- Wiki Modding Guide
Feel free to pm me
Or drop into #factorio on irc.esper.net
~FreeER=Factorio Modding
- Factorio Wiki
- My Factorio Modding Guide
- Wiki Modding Guide
Feel free to pm me
Or drop into #factorio on irc.esper.net
Re: [Guide] Modding in 0.3.0 introduction
Yeah, they are all awesome !
also, I need to change the name of all items used in recipes to use underscores?:
because gold-ore is a variable and it interpretates it as gold - ore, so do I need to change the name to gold_ore?
also, I need to change the name of all items used in recipes to use underscores?:
Code: Select all
ingredients= { gold-ore= 1 },
Re: [Guide] Modding in 0.3.0 introduction
We changed the names of the properties. Not the names of the game elements. So we still have "iron-plates", "copper-ore", etc. Therefore there should be the "gold-ore". In your case
This was not an easy decision because it creates some inconsistencies in the naming, however it saves a lot of typing for the property names.
Code: Select all
ingredients = { ["gold-ore"] = 1},
Re: [Guide] Modding in 0.3.0 introduction
Also what about this error:
Content Title
Content Title
Code: Select all
Cannot load lua script
G:/F\factorio_0.3.0.3945\mods\F-mod\data.lua. Error:
...\Factorio_0.3.0.3945\data\core\lualib\dataloader.lua:12: table index is nil
Re: [Guide] Modding and Scripting changes in 0.3.0
It was a lot of work However we wanted to make the needed radical changes to the mod suppost as soon as possible when there are still not that many mods. Also the changes we introduced should give modders way more powers.FreeER wrote: just imagine how much they've put into this update:
They had to figure out the best way to set it up
then they had to convert the base 'mod'
and test it to make sure everything worked
Then they have to write up a wiki for everything
AND THEN they have to put up with everyone who gets confused by the update
Not sure where this is exactly raised. I had a look into the dataloader (you can see that one too ) and saw the following on line 12:ficolas wrote: Also what about this error:
Content Title
CODE: SELECT ALL
Cannot load lua script
G:/F\factorio_0.3.0.3945\mods\F-mod\data.lua. Error:
...\Factorio_0.3.0.3945\data\core\lualib\dataloader.lua:12: table index is nil
Code: Select all
...
self.raw[e.type] = t
...
btw. I have updated the OP with links to some scripting documentation I put up on the wiki.
Re: [Guide] Modding and Scripting changes in 0.3.0
but this G:/F\factorio_0.3.0.3945\mods\F-mod\data.lua is the file where the files are required, do that mean that there is one prototipe that haves no type?
Edit: Recipes now have a type, that was the problem. thx.
Edit: Recipes now have a type, that was the problem. thx.
Last edited by ficolas on Sat Mar 30, 2013 10:43 pm, edited 1 time in total.
Re: [Guide] Modding and Scripting changes in 0.3.0
My guess is, that you missed type and name property in recipe specification.ficolas wrote:but this G:/F\factorio_0.3.0.3945\mods\F-mod\data.lua is the file where the files are required, do that mean that there is one prototipe that haves no type?
Re: [Guide] Modding and Scripting changes in 0.3.0
yup, I didnt know that recipes now have type, I knew they had name, but didnt know anything about type.kovarex wrote:My guess is, that you missed type and name property in recipe specification.ficolas wrote:but this G:/F\factorio_0.3.0.3945\mods\F-mod\data.lua is the file where the files are required, do that mean that there is one prototipe that haves no type?
Re: [Guide] Modding and Scripting changes in 0.3.0
Code: Select all
data:extend({
{
type = "recipe",
name = "gold-furnace",
result= "gold-plate",
ingredients= { ["gold-ore"]= 1 }, --this line.
energy_required= 500,
category= "smelting"
},
{
type = "recipe",
name = "silver-furnace",
result= "silver-plate",
ingredients= { ["silver-ore"]= 1 },
energy_required= 500,
category= "smelting"
}
})
line 6.
} expected near =
Re: [Guide] Modding and Scripting changes in 0.3.0
Actually the ingredients format has changed now it is a list of pairs instead of map (you can see this for instance in the base/prototypes/recipe/recipe.lua) so in your case it should be:
Code: Select all
...
ingredients = {
{ "gold-ore", 1}
}
Re: [Guide] Modding and Scripting changes in 0.3.0
Code: Select all
data:extend({
{
type = "recipe",
name = "gold-furnace",
result= "gold-plate",
ingredients = {{ "gold-ore", 1}},
energy_required= 500,
category= "smelting"
{
type = "recipe",
name = "silver-furnace",
result= "silver-plate",
ingredients = {{ "silver-ore", 1}},
energy_required= 500,
category= "smelting"
}
})
why...