entity.energy inserter
entity.energy inserter
Could anybody explain how entity.energy works in case of inserter... I have tried to figure it out but I have no idea how its works.
Lenovo Y580 8GB Ram GF660m 128GB SSD W7
Re: entity.energy inserter
It's the amount of energy left in the buffer of the entity...Beyond that I don't really know
It can be 0 both when the device has no energy and when the device is using ALL of it's energy (there's really no way to tell).
Otherwise, I think, it's value is buffer size - current usage.
Wish I could help you more here
I'll take a look at the source and see if I can understand any more (but I did that back when i was trying to figure out how to damage steam engines with Dysoch)...
It can be 0 both when the device has no energy and when the device is using ALL of it's energy (there's really no way to tell).
Otherwise, I think, it's value is buffer size - current usage.
Wish I could help you more here
I'll take a look at the source and see if I can understand any more (but I did that back when i was trying to figure out how to damage steam engines with Dysoch)...
Re: entity.energy inserter
Thx for answer.
I have to find way do change inserter power usage during the game useing of course lua script. Any idea how to do this?
I have to find way do change inserter power usage during the game useing of course lua script. Any idea how to do this?
Lenovo Y580 8GB Ram GF660m 128GB SSD W7
Re: entity.energy inserter
I wrote the large block of text below first and then thought of this right before I posted , not sure what would be the easiest, but probably this one:
make several inserters with different energy costs in the prototypes and then change the type of inserter (destroy old and replace with new inserter that has the appropriate energy cost) when it's output target distance changes (this only applies to the inserters that do the teleporting across a distance, not the ones that receive the items and place it down next to them, since the energy cost for that shouldn't actually change in-game).
Originally written text below:
Well, off the top of my head (and looking at telelogistics control.lua) I'd say something like:
before the line that transfers the items (740?) you'd calculate the distance between the inserters using local dis = util.distance(glob.teleins.connections[k], glob.teleins.connections[k][1]) and then use an algorithm like local energyConsumption = dis * basicEnergyCost, where basicEnergyCost is a variable (probably in glob) that holds the energy cost when the inserters are at a distance of 1. If this makes the energy cost too high for larger distances you could use math.pow(dis, 0.5) instead of just dis, which would use the square root of distance (and thus, a lower energyConsumption), the algorithm that you end up with is going to be tweaked depending on how you want it balanced.
Then check if the teleinserter has enough energy for that and if so remove that energy from the buffer and transfer items
if glob.teleins.connections[k].energy > energyConsumption then
glob.teleins.connections[k].energy = glob.teleins.connections[k]-energyConsumption
//code to complete transfer of items
end
So, assuming 740 is the transfer code it'd look like
Of course, this assumes that their buffer is large enough to make the transfers feasible at a distance...I can't remember now how the buffers are determined, but I think it's based on the amount of energy that the entities use (specified in prototype). If so you may need a way to prevent the inserters from using energy ingame so that only the lua code affects their energy (as far as I know the only way to do that is entity.active=false, but if they were never active you'd probably have to take control of the inserters picking up and dropping off items as well...)
make several inserters with different energy costs in the prototypes and then change the type of inserter (destroy old and replace with new inserter that has the appropriate energy cost) when it's output target distance changes (this only applies to the inserters that do the teleporting across a distance, not the ones that receive the items and place it down next to them, since the energy cost for that shouldn't actually change in-game).
Originally written text below:
Well, off the top of my head (and looking at telelogistics control.lua) I'd say something like:
before the line that transfers the items (740?) you'd calculate the distance between the inserters using local dis = util.distance(glob.teleins.connections[k], glob.teleins.connections[k][1]) and then use an algorithm like local energyConsumption = dis * basicEnergyCost, where basicEnergyCost is a variable (probably in glob) that holds the energy cost when the inserters are at a distance of 1. If this makes the energy cost too high for larger distances you could use math.pow(dis, 0.5) instead of just dis, which would use the square root of distance (and thus, a lower energyConsumption), the algorithm that you end up with is going to be tweaked depending on how you want it balanced.
Then check if the teleinserter has enough energy for that and if so remove that energy from the buffer and transfer items
if glob.teleins.connections[k].energy > energyConsumption then
glob.teleins.connections[k].energy = glob.teleins.connections[k]-energyConsumption
//code to complete transfer of items
end
So, assuming 740 is the transfer code it'd look like
Code: Select all
if glob.teleins.connections[k][1].heldstack == nil then
local energyConsumption = util.distance(glob.teleins.connections[k], glob.teleins.connections[k][1]) * basicEnergyCost
if glob.teleins.connections[k].energy > energyConsumption then --if inserter has enough energy
glob.teleins.connections[k].energy = glob.teleins.connections[k]-energyConsumption --drain energy
glob.teleins.connections[k][1].heldstack = {name = glob.teleins[k].heldstack.name, count = glob.teleins[k].heldstack.count}
glob.teleins[k].heldstack = nil
glob.teleins[k].active = true
end
end
Re: entity.energy inserter
Once again thx for answer,
I though about calculating distance and then multiple it by factor of "primary consumption", and then manipulate energy, but when I try to manipulate entity.energy some strange thing happen. When I set energy_per_movement and energy_per_rotation to 0 device seems to be not powered even if I place electric pole near to it. And entity.power is allways = 0. When I manually (script) change its power to >0 nothing happen, and in next tick its again 0 (unless I destroy electric pole near to it, then its hold entity.power value but don't take any item from chest/belt, this state is equal to entity.active=false).
When I define energy_per_movement and energy_per_rotation to different value then 0 I have this result:
energy_per_movement=1000 energy_per_rotation=1000 then Power consumption is 6,3kW
energy_per_movement=10000 energy_per_rotation=10000 then Power consumption is 63kW
energy_per_movement=50000 energy_per_rotation=50000 then Power consumption is 315kW
So its linear.
But when I was trying to change entity.power value really strange thing happen. Device stop working, or working some time then stop, and then again start... and so on.... Pulse Width Modulation
So average power usage was smaller then max, but never go bellow 60-70% of max. So, since somebody doesn't explain how to use entity.power is aspect of inserter its useless to me.
I have tried to add to prototype definition:
drain = "10kW" - WORKING
energy_usage = "100kW", - NOT WORKING
So I think that only way is to:
When I add several new inserter this list will be huge.... how to avoid this?
I was trying to create only entity prototype without item prototype but I have get an error message. (116550 its power in W, so its 116,55kW)
Always the same message but referring to different entity.
I though about calculating distance and then multiple it by factor of "primary consumption", and then manipulate energy, but when I try to manipulate entity.energy some strange thing happen. When I set energy_per_movement and energy_per_rotation to 0 device seems to be not powered even if I place electric pole near to it. And entity.power is allways = 0. When I manually (script) change its power to >0 nothing happen, and in next tick its again 0 (unless I destroy electric pole near to it, then its hold entity.power value but don't take any item from chest/belt, this state is equal to entity.active=false).
When I define energy_per_movement and energy_per_rotation to different value then 0 I have this result:
energy_per_movement=1000 energy_per_rotation=1000 then Power consumption is 6,3kW
energy_per_movement=10000 energy_per_rotation=10000 then Power consumption is 63kW
energy_per_movement=50000 energy_per_rotation=50000 then Power consumption is 315kW
So its linear.
But when I was trying to change entity.power value really strange thing happen. Device stop working, or working some time then stop, and then again start... and so on.... Pulse Width Modulation
So average power usage was smaller then max, but never go bellow 60-70% of max. So, since somebody doesn't explain how to use entity.power is aspect of inserter its useless to me.
I have tried to add to prototype definition:
drain = "10kW" - WORKING
energy_usage = "100kW", - NOT WORKING
So I think that only way is to:
But how to make new inserter that isn't display on player crafting page? ...here:FreeER wrote:make several inserters with different energy costs in the prototypes and then change the type of inserter (destroy old and replace with new inserter that has the appropriate energy cost) when it's output target distance changes (this only applies to the inserters that do the teleporting across a distance, not the ones that receive the items and place it down next to them, since the energy cost for that shouldn't actually change in-game).
When I add several new inserter this list will be huge.... how to avoid this?
I was trying to create only entity prototype without item prototype but I have get an error message. (116550 its power in W, so its 116,55kW)
Always the same message but referring to different entity.
Lenovo Y580 8GB Ram GF660m 128GB SSD W7
Re: entity.energy inserter
Some new info on entity.energy
This explains your results with movement/rotation consumption. As for manually increasing entity.energy, you can no longer increase it higher than it's buffer_capacity which at that time was 0 (which is shame...I used to do that when testing new machines and give them 100000000000 power lol)kovarex wrote:The buffer_capacity can be specified, but it is automatically set (overwriten) for some kind of entities:
Inserter, Mining Drill, Furnace, Assembling machine, Lab maybe some other.
The reason for this is, that the buffer is calculated to fit the needs of the machine (depending on speed and rotation/extension consumption for inserter, depending on modules for the rest).
For the particular usage (of the mod telelogistics). You can set the rotation/extension consumption higher or just drain the electricity for some time and store into a variable how much did you accumulate for the entity, once you have enough, you can make the needed transfer.
Anyway, as this is expected behavior I'm moving this to not a bug.
If you think that modders should be able to specify the buffer to not be overwritten in some cases, you can set it as modding interface request.
Hm, I think that the only item prototype needed for an inserter is for what is returned when you mine it, if I'm not forgetting something, then all you need to do there is make all of your teleinserters return the first teleinserter when they're mined (or if you create multiple power 'tiers' that require separate research then each would return the lowest from their tier).darius456 wrote:I was trying to create only entity prototype without item prototype but I have get an error message. (116550 its power in W, so its 116,55kW)