Page 1 of 1

General formatting help?...

Posted: Thu Jun 29, 2017 10:38 pm
by Volvith
Hi everyone,

So i've been messing around with a few mods for a couple of days now, and i've kind of created a mod that works, but doesn't. (The entire code package is listed below.)
The mod is an attempt to disable hand-crafting and force the player to use automation.
For this, i have an already existing mod that i've modified, called "no hand crafting".

The newly created burner assembling machine needs to only be able to access 19 or 20 basic items for crafting, for balancing reasons.
For this, i had the idea of adding a new category, and assigning those 19/20 items to that category.
Then i would add the newly created category to the assembling_machine_1/2/3, so that those still had access to the same items.

The creation of the assembler works, inserting it in the player inventory on game start works as well, but i have managed to, rather significantly, fuck up the data-updates.lua (i think).
What i notice in game, is that the burner assembler does exist, is handed to me on game init, but shows no craftable items, most likely with the categories as a point of failure.
In addition to that, the other assemblers do not show the modified items in their lists, but the items are present in my inventory.

The data-updates.lua file contains the base mod's recipe's category edit, along with the addition of the new category to the base assemblers.
I'm not really sure how to properly format data.raw functions for category (or any other) edits, and i've tried a numerous amount of combinations of different methods found on this forum and google in general, to no avail.

TL;DR: data-updates.lua provided in spoiler #4 below, is probably broken as shit. Any advice on how to format it?...
data.lua
control.lua
recipe-category.lua
data-updates.lua
entities.lua
item.lua
recipe.lua
P.S. Sorry if the post is awfully long, i'm not entirely sure what's causing the issue, so this might save a lot of stumbling around in the dark... :3
P.P.S. I have to add that a significant amount of this code was frankensteined to work. In addition to that, i probably only know for 80% how everything works, so bear that in mind when posting a reply. Cheers! ;P

Re: General formatting help?...

Posted: Fri Jun 30, 2017 10:51 am
by Choumiko
I don't mess much with prototypes in my mods, but it looks like it should work.
One thing i think might be an issue:
In data.lua remove the line: require ("data-updates")
(data-updated.lua and data-final-fixes.lua are loaded autmatically at the correct time by Factorio http://lua-api.factorio.com/latest/Data-Lifecycle.html )
Shouldn't matter i think, but it's intended that data-updates is executed after each mod has loaded its data.lua

data-updates:
For compatibility with other mods that might add/remove crafting categories you should use

Code: Select all

table.insert(data.raw["assembling-machine"]["assembling-machine-1"].crafting_categories, "automata-reworked")
--same for the other assemblers
This will only add your category, instead of overwriting every category that might have been already added by another mod

For debugging i'd add a data-final-fixes.lua with following content:

Code: Select all

log("Recipe categories")
log(data.raw.recipe["wooden-chest"].category)
--same as above for each item where you want to see the category
log("Assembler categories")
log(serpent.block(data.raw["assembling-machine"]["assembling-machine-1"].crafting_categories))
--same as above for each assembler where you want to see the categories
This will write to factorio-current.log:
0.940 Loading mod ModuleInserter 2.0.3 (data-final-fixes.lua)
0.943 Script data-final-fixes.lua:141: Recipe categories
0.943 Script data-final-fixes.lua:142: nil
0.944 Script data-final-fixes.lua:144: Assembler categories
0.944 Script data-final-fixes.lua:145: {
"crafting",
"crafting-machine"
}
(numbers will be different for you, also i inserted it into the ModuleInserter mod, search for your mods name instead)

or as an alternative you can add the following in the on_init part in control.lua:

Code: Select all

game.print("wooden chest: " .. game.recipe_prototypes["wooden-chest"])
game.print("am1: " .. serpent.block(game.entity_prototypes["assembling-machine-1"].crafting_categories))
this should print the info whenever you start a new game.
This will also be the 100%, always accurate categories that Factorio uses (the data-final-fixes might be wrong if you have another mod enabled that for whatever reason changes them in their own data-final-fixes and gets run after your mod)

Re: General formatting help?...

Posted: Fri Jun 30, 2017 5:47 pm
by Volvith
EDIT:
Holy mother of shit that is one long reply...
In case of need to skip the ramblings and updates, at the bottom two boxes, from the "The "Kinda Works" Part:" to the bottom.
Cheers. xD

2nd EDIT:
So, turns out, like... "0" is not the same as nil.
...
Uhm, so... Fixed the last part.
Ah um sthoopit.
Anyways, thanks again. :3


First off, huge thanks for the detailed reply!
I have to admit that i got my mod to work before i read your post, but i must say that i still found it quite helpful regardless of that. :)

Choumiko wrote: One thing i think might be an issue:
In data.lua remove the line: require ("data-updates")
(data-updated.lua and data-final-fixes.lua are loaded autmatically at the correct time by Factorio)
Shouldn't matter i think, but it's intended that data-updates is executed after each mod has loaded its data.lua
I think i quickly mashed the data.lua together after splitting up my mod in different files.
Yes, i coded the entire thing in the data.lua file before then. :/
Anyhow, when you learn code for 8 hours straight, and it's 4:32 AM, you tend to make mistakes... xD
Thanks for the tip though, i wasn't entirely sure whether the data.lua needed the data-updates as, while i knew that it didn't need data-final-fixes, it didn't seem to break anything.
Choumiko wrote: data-updates:
For compatibility with other mods that might add/remove crafting categories you should use

Code: Select all

table.insert(data.raw["assembling-machine"]["assembling-machine-1"].crafting_categories, "automata-reworked")
--same for the other assemblers
This will only add your category, instead of overwriting every category that might have been already added by another mod
That's actually a really good tip for compatibility.
(Note to self, do not try to data.raw edit non-existent values for an hour... If something's fucked and you can't find what, check everything, as something else if probably fucked. -_-)
Choumiko wrote: For debugging i'd add a data-final-fixes.lua with following content:

Code: Select all

log("Recipe categories")
log(data.raw.recipe["wooden-chest"].category)
--same as above for each item where you want to see the category
log("Assembler categories")
log(serpent.block(data.raw["assembling-machine"]["assembling-machine-1"].crafting_categories))
--same as above for each assembler where you want to see the categories
This will write to factorio-current.log:
0.940 Loading mod ModuleInserter 2.0.3 (data-final-fixes.lua)
0.943 Script data-final-fixes.lua:141: Recipe categories
0.943 Script data-final-fixes.lua:142: nil
0.944 Script data-final-fixes.lua:144: Assembler categories
0.944 Script data-final-fixes.lua:145: {
"crafting",
"crafting-machine"
}
(numbers will be different for you, also i inserted it into the ModuleInserter mod, search for your mods name instead)

or as an alternative you can add the following in the on_init part in control.lua:

Code: Select all

game.print("wooden chest: " .. game.recipe_prototypes["wooden-chest"])
game.print("am1: " .. serpent.block(game.entity_prototypes["assembling-machine-1"].crafting_categories))
this should print the info whenever you start a new game.
This will also be the 100%, always accurate categories that Factorio uses (the data-final-fixes might be wrong if you have another mod enabled that for whatever reason changes them in their own data-final-fixes and gets run after your mod)
When i injected the log code in the first quote into the data-final-fixes, it worked perfectly.
However, as my code is working (ish, i'll get to that later) now, it didn't register a log.
I'm assuming that the "log" function is kind of like a "on_crash" function until told otherwise.

The game.print works:

Code: Select all

script.on_init(function()
	pcall(function()
		game.print("wooden chest: " .. game.recipe_prototypes["wooden-chest"])
		game.print("am1: " .. serpent.block(game.entity_prototypes["assembling-machine-1"].crafting_categories))
		
		for _, player in pairs(game.players) do
			player.insert{name = "burner-assembling-machine", count = 1}
		end
		
	end)
end)
Basically just checking whether this is what you meant with "in the on_init part". :)


The "Kinda Works" Part:
So, as i said, my mod works, kinda.
This is what i can't figure out:

Code: Select all

if data.raw["assembling-machine"]["burner-assembling-machine"] then
	data.raw["simple-entity"]["stone-rock"].minable.count = "0"
	data.raw["simple-entity"]["stone-rock"].loot.probability = "0"
end
What i'm trying to do here is removing both the mining drops and loot drops from the large rocks scattered around the map.
And it worked when i tried to make it unmineable, which was my first plan that just didn't work out.

However, when i try to run the game with this code in either my data-updates, or data-final-fixes files, it gives me the following error on start-up:
Error while loading entity prototype "stone-rock" (simple-entity): No such node (item)
Modifications: base > Automatrius
I checked the base-code, and the entity is definitely still there, in the prototypes\entity\demo-doodads.lua file, and the type and name, in that order, check out.
So why would it feed back a "no such node" error on start-up? o-0

Again, thanks for the help, i really appreciate it! :D