To reproduce: place an assembler building e.g. pipes, insert 10 iron plates and select the machine.
Code: Select all
/c game.players[1].selected.crafting_progress = 1
Code: Select all
/c game.players[1].selected.crafting_progress = 1
How to complete the crafing process properly?
Code: Select all
local recipe = assembler.get_recipe()
local assembler_input = assembler.get_inventory(defines.inventory.assembling_machine_input)
assembler.crafting_progress = 1
for _, ingredient in ipairs(recipe.ingredients) do
assembler_input.remove{name = ingredient.name, count = ingredient.amount}
end
Not sure what exactly you're doing, but pretty sure that will craft for free even with insufficient ingredients.BuilderOfAges wrote: ↑Sun Sep 30, 2018 10:58 amI did it like this, which seems to work:
Code: Select all
local recipe = assembler.get_recipe() local assembler_input = assembler.get_inventory(defines.inventory.assembling_machine_input) assembler.crafting_progress = 1 for _, ingredient in ipairs(recipe.ingredients) do assembler_input.remove{name = ingredient.name, count = ingredient.amount} end
Ah, the anvil thing. Hadn't thought to much about it last time. If the anivil (==assembler?) uses a burner energy source you could manipulate the energy instead of the progress directly. I.e. add a bit of energy with every hammer stroke (would also be visible in the tooltip as a short spike). Ofc you'd have to tune the crafting speed/consumpition to exactly match your desired stroke count. But it'd remove the need to manually do resource reduction.BuilderOfAges wrote: ↑Mon Oct 01, 2018 4:23 pmYes it's only a fragment, focusing on taking out the necessary ingredients. You'd have to check yourself whether all the necessary ingredients were already present.
In my case, I wanted to make an anvil where the recipe never completes automatically, but every time you add a hammer the crafting progress increases by a third.
Thanks :). I don't get much (read: none) feedback on it. Nice to know if someone finds it useful, even if it's just for using the code (that was after all the original idea).BuilderOfAges wrote: ↑Mon Oct 01, 2018 4:23 pmP.S.: thanks for hand-crank generator BTW. I want to add something similar to my mod, will definitely take a look at your code.