Page 1 of 1
Bug when trying to set burner.currently_burning
Posted: Sun Jun 18, 2017 12:00 am
by kumpu
Alright so I get this error:
http://i.imgur.com/lJgJyNA.png
when running this code:
Code: Select all
140: c = game.surfaces[1].create_entity{name = "car", force = game.forces.neutral, position = {x=0,y=0}}
141: c.burner.currently_burning = game.item_prototypes["coal"]
The API documentation states that "currently_burning" is of type LuaItemPrototype. So why is it talking about a string?
Re: Bug when trying to set burner.currently_burning
Posted: Sun Jun 18, 2017 2:14 am
by Rseding91
The write method for the property was actually looking for a string. I changed it for the next version of 0.15 so it accepts both a string or the item prototype as the docs say.
Re: Bug when trying to set burner.currently_burning
Posted: Sun Jun 18, 2017 2:25 pm
by kumpu
Thanks! How would I use the string? Item prototype name?
Re: Bug when trying to set burner.currently_burning
Posted: Sun Jun 18, 2017 2:33 pm
by Rseding91
kumpu wrote:Thanks! How would I use the string? Item prototype name?
Yes.
Re: Bug when trying to set burner.currently_burning
Posted: Sun Jun 18, 2017 4:02 pm
by kumpu
Well either I'm missing something or this is another bug, but setting it to e.g. "coal" does not actually update LuaBurner::remaining_burning_fuel, as the docs say...
Re: Bug when trying to set burner.currently_burning
Posted: Sun Jun 18, 2017 4:11 pm
by kumpu
May I suggest that you add a LuaBurner::consume(energy) function? My use case is that I have a car entity (it's a helicopter mod) that should consume power at all times when the rotor is spinning, not only when you press WASD. A function that would handle the consumption automatically, uses available fuel slots and shows the out of fuel symbol when empty, just like it does when you accelerate manually, would be really nice.
Re: Bug when trying to set burner.currently_burning
Posted: Sun Jun 18, 2017 4:25 pm
by Rseding91
kumpu wrote:Well either I'm missing something or this is another bug, but setting it to e.g. "coal" does not actually update LuaBurner::remaining_burning_fuel, as the docs say...
It automatically handles reducing remaining energy if it's above the amount coal can handle. If it's at 0, then it still stays at 0 after setting it.
Re: Bug when trying to set burner.currently_burning
Posted: Sun Jun 18, 2017 4:53 pm
by kumpu
Rseding91 wrote:It automatically handles reducing remaining energy if it's above the amount coal can handle. If it's at 0, then it still stays at 0 after setting it.
I see. So instead of a nice convenient consume() function I have to use smth like this
Code: Select all
self.baseEnt.burner.remaining_burning_fuel = self.baseEnt.burner.remaining_burning_fuel - baseEngineConsumption
if self.baseEnt.burner.remaining_burning_fuel <= 0 then
if self.baseEnt.burner.inventory.is_empty() then --force display the out of fuel symbol
local mod = self.baseEnt.effectivity_modifier
self.baseEnt.effectivity_modifier = 0
self.baseEnt.passenger.riding_state = {acceleration = defines.riding.acceleration.accelerating, direction = defines.riding.direction.straight}
self.baseEnt.effectivity_modifier = mod
else
local fuelItemStack = nil
for i = 1, #self.baseEnt.burner.inventory do
if self.baseEnt.burner.inventory[i] and self.baseEnt.burner.inventory[i].valid_for_read then
fuelItemStack = self.baseEnt.burner.inventory[i]
break
end
end
if fuelItemStack then
self.baseEnt.burner.currently_burning = fuelItemStack.prototype.name
self.baseEnt.burner.remaining_burning_fuel = fuelItemStack.prototype.fuel_value
self.baseEnt.burner.inventory.remove({name = fuelItemStack.name})
end
end
end
Not pretty, but eh it works so...
Re: Bug when trying to set burner.currently_burning
Posted: Sun Jun 18, 2017 5:13 pm
by Rseding91
A small thing: "fuelItemStack.prototype.name" can just be "fuelItemStack.name"
Re: Bug when trying to set burner.currently_burning
Posted: Sun Jun 18, 2017 5:28 pm
by kumpu
Rseding91 wrote:A small thing: "fuelItemStack.prototype.name" can just be "fuelItemStack.name"
Right, thanks