Page 1 of 1

Set belt_to_ground_type?

Posted: Thu Mar 24, 2016 3:09 am
by LithDev
So I am trying to make a new item (extraction-belt), implemented as a transport-belt-to-ground.
I have this in my Entity.lua:

Code: Select all

belt_to_ground_type = "output",
and this in my control.lua (where I am creating the extraction-belt entity):

Code: Select all

script.on_event(defines.events.on_built_entity, function(event)
	if event.created_entity.name == "extraction-belt" then
		table.insert(global.belt_extractors, event.created_entity)
		game.get_player(1).print("belt to ground type: " .. event.created_entity.belt_to_ground_type)
	end
end)
every time I place one in game, it outputs" belt to ground type: input".

Is there any way to set it up as an input, or do I need a work-around?

Re: Set belt_to_ground_type?

Posted: Thu Mar 24, 2016 4:42 am
by Choumiko
Try setting the type to output instead of printing the type. I think it's not intended for underground belts to only have an output.

Re: Set belt_to_ground_type?

Posted: Thu Mar 24, 2016 4:50 am
by LithDev
no dice, belt_to_ground_type is Read-Only

Re: Set belt_to_ground_type?

Posted: Thu Mar 24, 2016 8:04 am
by Choumiko
Oh right, try this one:

Code: Select all

script.on_event(defines.events.on_built_entity, function(event)
   if event.created_entity.name == "extraction-belt" then
    local old_e = event.created_entity
    local new_e = {name=old_e.name, direction=old_e.direction, position=old_e.position, force=old_e.force, type="output"}
    local surface = old_e.surface
    old_e.destroy()
    local created_entity = surface.create_entity(new_e)
    table.insert(global.belt_extractors, created_entity)
   end
end)
This will destroy the created entity and create a new one in the same spot with output as type. At least it should, haven't tested it.
You might need to adjust the direction if the belt ends up facing the wrong way.

Re: Set belt_to_ground_type?

Posted: Thu Mar 24, 2016 2:25 pm
by LithDev
This is ALMOST perfect. It places the right entity and everything (it did need to be rotated), but the sprite for pre-placing it is still wrong.
http://imgur.com/JgyjWfe
It's subtle enough that I'm not going to worry about it too much