electric trains
electric trains
Hi,
I am trying to create a mod so one can use electric locomotives instead of "diesel" ones.
As it is not easy to make electrifiable rails, I planned to do a locomotive which could "store" energy with batteries (same behavior than the roboport) when in stations, and then use it when running.
So I tried first to modify the base lua files, by changing the energy source from "burner" to "electric", and setting some parameters, as max input power and energy storage capacity. I copied the parameters from the roboport and adapted the values.
However, when I run the game, the locomotive is said to have no electricity plugged, even when I put a pole near it. If I try to open the locomotive (its inventory), the game crashes.
Did I messed up something somewhere ?
EDIT : corrected spelling error
I am trying to create a mod so one can use electric locomotives instead of "diesel" ones.
As it is not easy to make electrifiable rails, I planned to do a locomotive which could "store" energy with batteries (same behavior than the roboport) when in stations, and then use it when running.
So I tried first to modify the base lua files, by changing the energy source from "burner" to "electric", and setting some parameters, as max input power and energy storage capacity. I copied the parameters from the roboport and adapted the values.
However, when I run the game, the locomotive is said to have no electricity plugged, even when I put a pole near it. If I try to open the locomotive (its inventory), the game crashes.
Did I messed up something somewhere ?
EDIT : corrected spelling error
Re: electric trains
the diesel trains have a power attribute, and you can tell it what the max and current are. you can also remove the inventory spots for fuel, which makes it seem electric.
from there, you need some way to add power to it, maybe have it charge off of local robo-ports type thing? or add a consumer under the train when it's parked and have that power up (like an accumulator) then when the train starts up again, pull the consumer and set the trains power to the consumers. I was also looking into this idea as well
from there, you need some way to add power to it, maybe have it charge off of local robo-ports type thing? or add a consumer under the train when it's parked and have that power up (like an accumulator) then when the train starts up again, pull the consumer and set the trains power to the consumers. I was also looking into this idea as well
Will code for Food. I also have 11+ mods!
Re: electric trains
Electric locomotives are already implemented in 5dim-trains mod. Code-wise, they're not true electric devices, as dummy coal item is inserted into them every once in a while.
From my experience, entity prototype definitions are misleading at best. Even though they have field 'energy_source' and there's 'type' in that table, generally you can not define the former in any way, that is not present in vanilla for that type of entity.
As for crash, did your new energy_source had 'fuel_inventory_size' despite being electric? Pure guess, but usually syntactically correct definitions don't cause crashes even if not functioning correctly. There's also factorio_current.log in the root folder of factorio, sometimes it even manages to dump usable information about runtime errors. (Though its main goal in such case is to provide some crashlog understandable only by devs.)
From my experience, entity prototype definitions are misleading at best. Even though they have field 'energy_source' and there's 'type' in that table, generally you can not define the former in any way, that is not present in vanilla for that type of entity.
As for crash, did your new energy_source had 'fuel_inventory_size' despite being electric? Pure guess, but usually syntactically correct definitions don't cause crashes even if not functioning correctly. There's also factorio_current.log in the root folder of factorio, sometimes it even manages to dump usable information about runtime errors. (Though its main goal in such case is to provide some crashlog understandable only by devs.)
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.
I also update mods, some of them even work.
Recently I did a mod tutorial.
Re: electric trains
Thanks for your answers !
Adil => I removed the whole "energy_source" tag before creating the electric one, so yes I guess that the fuel_inventory_size tag has been removed with. I'll have a look @ the log when coming back home.
Vzyvily => Parhaps I can make an item which makes the train charge when in range by creating some behavior lua code. I'll try this
Adil => I removed the whole "energy_source" tag before creating the electric one, so yes I guess that the fuel_inventory_size tag has been removed with. I'll have a look @ the log when coming back home.
Vzyvily => Parhaps I can make an item which makes the train charge when in range by creating some behavior lua code. I'll try this
Re: electric trains
To make trains with unlimited energy, this is the code that I just made:
data-updates:
control:
I know there is a better way but I think some stuff from the wiki got removed from the last time I was looking up electric trains... I made all this in just afew minutes so there will be issues...
data-updates:
Code: Select all
--data.raw["locomotive"]["diesel-locomotive"].max_power = "60000kW" --enable for super fast trains.
data.raw["locomotive"]["diesel-locomotive"].energy_source.fuel_inventory_size = 0
--raw[<TYPE>][<NAME>]
Code: Select all
require "defines"
game.on_init(function() On_Load() end)
game.on_load(function() On_Load() end)
game.on_event(defines.events.on_tick, function() On_Tick() end)
game.on_event(defines.events.on_built_entity, function(event) On_Built(event) end)
game.on_event(defines.events.on_robot_built_entity, function(event) On_Built(event) end)
game.on_event(defines.events.on_preplayer_mined_item, function(event) On_Removed(event) end)
game.on_event(defines.events.on_robot_pre_mined, function(event) On_Removed(event) end)
game.on_event(defines.events.on_entity_died, function(event) On_Removed(event) end)
function On_Load()
if not global.trainList then
global.trainList = {}
end
end
function On_Tick()
for i=1,#global.trainList do
global.trainList[i].energy = 500000000
end
end
function On_Built(event)
local entity = event.created_entity
if entity.name == "diesel-locomotive" then
global.trainList[#global.trainList+1] = entity
end
end
function On_Removed(event)
local entity = event.entity
if entity.name == "diesel-locomotive" then
--this needs the index... to lazy and it's a copy from another mod that does this same thing...
--that other mod had the issue and wasn't fixed...
table.remove(global.trainList, entityIndex)
end
end
Will code for Food. I also have 11+ mods!
Re: electric trains
If I understand your code, it makes all trains in the game work with unlimited energy. Nice workaround, but I do not like the fact that it is free energy. You don't have to provide electri energy, charge traines, etc...
Did not have time to dig further for now, I'll tell you when I have something done.
Did not have time to dig further for now, I'll tell you when I have something done.
Re: electric trains
it does, but I was thinking it could have a new train added, like a solar train and it would only affect those. the recipe could be a normal train with electric engines, and an amount of solar panels and accumulators in the golden ratio amount.
or you could spend time to find out how to get them to charge off the network
you could even have it be something stupid like 4 times the ratio for the unlimited energy (100 accumulators with 84 solars.)
or you could spend time to find out how to get them to charge off the network
Will code for Food. I also have 11+ mods!
Re: electric trains
Yes, indeed, solar trains may be an easier solution... This doesn't seem realistic in any way, due to the power required by an electric locomotive. But if I don't find a way, then I'll turn to this, definitely.
Re: electric trains
OK, so I had a look and confirm that the game crashes if the train does not have any fuel_inventory_size parameter set. (I changed energy_source to electric type)
Also, I guess that the train says it is not plugged to the electrical network because it is not placed on the map, but on a rail segment. I tried to remove the "not-on-map" flag, but no difference. I'll have to find a way to make it belive it is plugged. Perhaps with an onTick function
EDIT :
I looked a bit more in the wiki about modding, and found a lot of interesting info. I tried to display the train's energy and got something like 10666.66666667 (600Kw equivalent in J I suppose). I tried to modify the value using simple lua commands in-game, but whatever I do the energy is reset to the above value. I guess there is an internal behavior for entities like trains which sets the energy depending on available fuel. If this is the case, this makes electric trains creation purely impossible (with / without batteries). Perhaps this explains why the mod you shown me does the "coal trick". I hope that developpers will add a real electric train feature shortly
Also, I guess that the train says it is not plugged to the electrical network because it is not placed on the map, but on a rail segment. I tried to remove the "not-on-map" flag, but no difference. I'll have to find a way to make it belive it is plugged. Perhaps with an onTick function
EDIT :
I looked a bit more in the wiki about modding, and found a lot of interesting info. I tried to display the train's energy and got something like 10666.66666667 (600Kw equivalent in J I suppose). I tried to modify the value using simple lua commands in-game, but whatever I do the energy is reset to the above value. I guess there is an internal behavior for entities like trains which sets the energy depending on available fuel. If this is the case, this makes electric trains creation purely impossible (with / without batteries). Perhaps this explains why the mod you shown me does the "coal trick". I hope that developpers will add a real electric train feature shortly
- Alekthefirst
- Fast Inserter
- Posts: 104
- Joined: Sat Feb 07, 2015 7:39 pm
- Contact:
Re: electric trains
Watts are defined as Joule per second, 106666.6 doesnt have any link to 600kW unless you can prove that 10666.6 is indeed some energy amount, if so, that would imply that the number points to the total energy usage of some action being performed over a VERY short period of time@xi@g@me wrote:10666.66666667 (600Kw equivalent in J I suppose)
Factorio is a game about automating everything. One day, i hope i can automate shitty signatures just like this one.
Re: electric trains
Try zero.@xi@g@me wrote:OK, so I had a look and confirm that the game crashes if the train does not have any fuel_inventory_size parameter set. (I changed energy_source to electric type)
I don't think this would really be possible via in-game commands as you need a reference to the actual train engine itself.@xi@g@me wrote:I tried to modify the value using simple lua commands in-game, but whatever I do the energy is reset to the above value. I guess there is an internal behavior for entities like trains which sets the energy depending on available fuel.
the way I showed did not use the "coal trick" and was a viable way of making electric trains, all that's needed is to get a way to charge them... or like I said, slap a solar label on it and call it a day.@xi@g@me wrote:If this is the case, this makes electric trains creation purely impossible (with / without batteries). Perhaps this explains why the mod you shown me does the "coal trick". I hope that developers will add a real electric train feature shortly
in fact, I'll see about working on my mods today and see if I can't get them out. I'll also try to build a charging set of trains as well and see how that goes. I'll also like the mods here so you can see how it works in practice.
Will code for Food. I also have 11+ mods!
-
- Filter Inserter
- Posts: 402
- Joined: Fri May 23, 2014 8:54 am
- Contact:
Re: electric trains
I hate to be a buzz kill but unless wube have done a pass in 0.12 on the train energy system you can't just set the energy. The coal trick was used in wagons (now 5dims train mod) because the train energy system is buggy/broken. You can't reliably read or write the energy from the train entity.
Re: electric trains
I had it working while I was testing on my original post and right now I am working on my mods to get them all updated to 0.12, after that we'll see.JamesOFarrell wrote:I hate to be a buzz kill but unless wube have done a pass in 0.12 on the train energy system you can't just set the energy. The coal trick was used in wagons (now 5dims train mod) because the train energy system is buggy/broken. You can't reliably read or write the energy from the train entity.
Will code for Food. I also have 11+ mods!
-
- Filter Inserter
- Posts: 402
- Joined: Fri May 23, 2014 8:54 am
- Contact:
Re: electric trains
Wube must have fixed the issues with it then which is nice, It was a pain having to use coal. The other issue with the way wagons did things was having a bunch of moving entities under the train to draw power, I always wanted to go back and change it so the entities were under the track instead so they don't move. should fix the FPS issue it caused by having lots of trains
Re: electric trains
I actually just got my mods up and working on the 0.12 update, and it seems that the max is 10666.6666... (coasting/stopped/just after setting to an insane amount) and when moving it will be 666.6666... before the setting of the value... I'm guessing it has something to do with the state or if it can move next tick or something... it seems very odd though...JamesOFarrell wrote:Wube must have fixed the issues with it then which is nice, It was a pain having to use coal. The other issue with the way wagons did things was having a bunch of moving entities under the train to draw power, I always wanted to go back and change it so the entities were under the track instead so they don't move. should fix the FPS issue it caused by having lots of trains
it switching to coasting
I will look to see if I can set it a better way but till then, I have a cheaty unlimited power train going in my mod tests...the way I'm setting the power:
Code: Select all
print("Pre Train #",i," power: ",global.trainList[i].energy)
global.trainList[i].energy = 500000000
print("Post Train #",i," power: ",global.trainList[i].energy)
Will code for Food. I also have 11+ mods!
Re: electric trains
vzybilly : the number I show you is the one I got by typing a command to get the energy roperty of a train which was running. If the train is stopped (no coal inside), the value is 0.
It is possible to get/change the values in game, by using the selection. I get inside the train, run it, the zoom at maximum. Put the cursor on my train, so it is "selected".
Then I just have to use game.player.selection.train to get the train object. From there I tried to read the values and modified them, concluding that whatever value I put, it comes back immediately to 10666.6666666667... (or 0 if no coal).
If the train has no fuel and I set an energy value, the train starts and stops immediately. Also, I tried to use the energy set trick on a train set to use electric energy_source instead of burner (with an accumulator capacity), but the behavior is the same.
So, I can't charge the train when it is stopped on a station with a charging device.
And, indeed, I had a look at wikipedia, 1J is effectively 1W/s. So I don't know why 10666.6666666667..., because the max power for the train is set to 600kW in the base lua file.
It is possible to get/change the values in game, by using the selection. I get inside the train, run it, the zoom at maximum. Put the cursor on my train, so it is "selected".
Then I just have to use game.player.selection.train to get the train object. From there I tried to read the values and modified them, concluding that whatever value I put, it comes back immediately to 10666.6666666667... (or 0 if no coal).
If the train has no fuel and I set an energy value, the train starts and stops immediately. Also, I tried to use the energy set trick on a train set to use electric energy_source instead of burner (with an accumulator capacity), but the behavior is the same.
So, I can't charge the train when it is stopped on a station with a charging device.
And, indeed, I had a look at wikipedia, 1J is effectively 1W/s. So I don't know why 10666.6666666667..., because the max power for the train is set to 600kW in the base lua file.
Re: electric trains
yes, the whole thing is quite odd, I've been playing with it for a good bit today but I have found that it is very odd and stupid, I wish there was a way to see what things are in the train but I keep getting userdata types which are pretty much a no go for printing... so far, the best way that I've found for using a train with no coal is to set fuel_inventory_size = 0 then in control:@xi@g@me wrote:vzybilly : the number I show you is the one I got by typing a command to get the energy roperty of a train which was running. If the train is stopped (no coal inside), the value is 0.
It is possible to get/change the values in game, by using the selection. I get inside the train, run it, the zoom at maximum. Put the cursor on my train, so it is "selected".
Then I just have to use game.player.selection.train to get the train object. From there I tried to read the values and modified them, concluding that whatever value I put, it comes back immediately to 10666.6666666667... (or 0 if no coal).
If the train has no fuel and I set an energy value, the train starts and stops immediately. Also, I tried to use the energy set trick on a train set to use electric energy_source instead of burner (with an accumulator capacity), but the behavior is the same.
So, I can't charge the train when it is stopped on a station with a charging device.
And, indeed, I had a look at wikipedia, 1J is effectively 1W/s. So I don't know why 10666.6666666667..., because the max power for the train is set to 600kW in the base lua file.
Code: Select all
function On_Tick()
for i=1,#global.trainList do
global.trainList[i].energy = 500000000
end
end
Will code for Food. I also have 11+ mods!
-
- Filter Inserter
- Posts: 952
- Joined: Sat May 23, 2015 12:10 pm
- Contact:
Re: electric trains
per tick value maybe?
multiply by 60 and you get 640k
multiply by 60 and you get 640k
Re: electric trains
Yes, just tested by adjusting max_power in the prototype and shifting it by 10s will shift the value by the same amount! I think this is the energy to be used this/next tick or something like thatratchetfreak wrote:per tick value maybe?
multiply by 60 and you get 640k
Now if only we could find out where the energy buffer is...
Will code for Food. I also have 11+ mods!
Re: electric trains
Ok, per watt, the max power per tick is 0.017777777777778 but the train's max power per watt per tick ends up being 0.016666666666667vzybilly wrote:Yes, just tested by adjusting max_power in the prototype and shifting it by 10s will shift the value by the same amount! I think this is the energy to be used this/next tick or something like thatratchetfreak wrote:per tick value maybe?
multiply by 60 and you get 640k
Now if only we could find out where the energy buffer is...
I feel safer in saying that it's a rounding error or something causing it because at the per watt per tick level, those two numbers look to close while being too far...
mostly just putting up my findings so far but I think I can effectively use this info now... also, still no clue about a buffer solution so I'll work on this abit more and see if I can't get things to work out more...
Will code for Food. I also have 11+ mods!