Page 1 of 1

[0.13.4] Input loaders are not set back to active state

Posted: Tue Jul 05, 2016 11:55 am
by y.petremann
I know that the loaders are not meant to be used, but they are still there and I know that a lot of modders would be glad to use them.

I've tried something with some stuff to see the comparison between loaders and inserters and found that targeted entities set inserter to active state but not loaders, this mean that only the loader's input (transport-belt) can set it to actve state, but if that transport belt is full, nothing could happens unless you refresh it.

Re: [0.13.4] Input loaders are not set back to active state

Posted: Tue Jul 05, 2016 12:01 pm
by Rseding91
It's not in the base game for a reason - it's not fully implemented.

Re: [0.13.4] Input loaders are not set back to active state

Posted: Tue Jul 05, 2016 12:26 pm
by y.petremann
Rseding91 wrote:It's not in the base game for a reason - it's not fully implemented.
I think that right that it's not fully implemented, but it's here and I think that some modders would use it, look at some mods like slipstream chest for example ...

For now this is the only thing I found that make it working improperly for general cases.

Re: [0.13.4] Input loaders are not set back to active state

Posted: Tue Jul 12, 2016 9:01 pm
by snowrabbit
I added the following control.lua to the loaders mod. It deactivates and activates them every now and then. This solves the problem that loaders stay deactivated even when they have work to do.

Code: Select all

script.on_init(function()
	if global.tickTable == nil then 
	  global.tickTable = { } 
	  global.loaderCount = 0
	  global.removedIndex = -1
	end
end)

script.on_load(function()
    if global.tickTable == nil then 
	  global.tickTable = { } 
	  global.loaderCount = 0
	end
end)

script.on_event(defines.events.on_built_entity, function(event) onBuild(event.created_entity) end)
script.on_event(defines.events.on_robot_built_entity, function(event) onBuild(event.created_entity) end)
script.on_event(defines.events.on_tick, function(event) onTick(event.tick) end)

function onBuild(entity)
	if entity.name == "loader" or entity.name == "fast-loader" or entity.name == "express-loader" then
	
		if global.removedIndex ~= -1 then
			loaders = global.tickTable[removedIndex]
			loaders[getEntityId(entity)] = entity
			global.removedIndex = -1
		else
	
			global.loaderCount = global.loaderCount + 1
			index = global.loaderCount % 240
			if global.tickTable[index] == nil then
				global.tickTable[index] = {}
			end
			
			global.tickTable[index][getEntityId(entity)] = entity
		
		end
		
		
		
	end
end

function onTick(tick)
	index = tick % 240
	local loaders = global.tickTable[index]
	
	if loaders == nil then return end
	
	for i,v in pairs(loaders) do
		if v and v.valid then
			v.active = false
			v.active = true
		else
			loaders[i] = nil
			removedIndex = index
		end
	end
	global.tickTable[index] = loaders

end

function getEntityId(entity)
	return "lldr:" .. entity.position.x .. "---" .. entity.position.y
end
I'm no LUA expert, but it did the trick for me and did not influence script update time in a significant way.

greets

Re: [0.13.4] Input loaders are not set back to active state

Posted: Thu Aug 04, 2016 7:37 am
by posila
Hi, we have decided to fix and support loader entity after all, even thought we don't plan to use it in vanilla for now.

Thanks for the report,
this will be fixed in 0.13.14

Re: [0.13.4] Input loaders are not set back to active state

Posted: Sat Aug 06, 2016 8:43 am
by atehxx
Yes yes yes thanks! :)