Hello!
Is it possible, to turn one thing into another after a certain recipe?
For example I have an object resembling a "Assembling mashine", in which I put the stuff for crafting the car (8 engine unit, 20 iron plates, 5 steel plates). After a certain time, this "Assembling mashine" becomes a car.
That is, the car is already on the ground and I can go, to fill it, sit down and go away.
Turn one thing into another
Re: Turn one thing into another
You can't turn one entity into another, but you can remove the assembling machine by calling destroy() on it and then create a new entity (the car) on the same spot by calling game.get_surface(1).create_entity().
Example code:
Example code:
Code: Select all
function replaceEntity(sourceEntity, targetEntityName)
local entity = game.get_surface(1).create_entity{
name = targetEntityName,
position = {sourceEntity.position.x, sourceEntity.position.y},
force = sourceEntity.force}
-- add code here to modify the new entity if required
sourceEntity.destroy()
end
Re: Turn one thing into another
Why would you hardcode game.get_surface(1) if you could just use sourceEntity.surface?
(Also instead of "position = {sourceEntity.position.x, sourceEntity.position.y}" you could just use "position = sourceEntity.position")
(Also instead of "position = {sourceEntity.position.x, sourceEntity.position.y}" you could just use "position = sourceEntity.position")
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!
Re: Turn one thing into another
Thanks for the tips. I'm still new to modding Factorio (besides a few quick fixes) and in new code I already use surfaces and other objects provided by the entities. It's probably time to revisit my old code and make these easy changes.prg wrote:Why would you hardcode game.get_surface(1) if you could just use sourceEntity.surface?
(Also instead of "position = {sourceEntity.position.x, sourceEntity.position.y}" you could just use "position = sourceEntity.position")