Bug when trying to set burner.currently_burning

This subforum contains all the issues which we already resolved.
Post Reply
User avatar
kumpu
Fast Inserter
Fast Inserter
Posts: 111
Joined: Wed Jun 07, 2017 10:10 am
Contact:

Bug when trying to set burner.currently_burning

Post 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? :?

Rseding91
Factorio Staff
Factorio Staff
Posts: 13209
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Bug when trying to set burner.currently_burning

Post 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.
If you want to get ahold of me I'm almost always on Discord.

User avatar
kumpu
Fast Inserter
Fast Inserter
Posts: 111
Joined: Wed Jun 07, 2017 10:10 am
Contact:

Re: Bug when trying to set burner.currently_burning

Post by kumpu »

Thanks! How would I use the string? Item prototype name?

Rseding91
Factorio Staff
Factorio Staff
Posts: 13209
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Bug when trying to set burner.currently_burning

Post by Rseding91 »

kumpu wrote:Thanks! How would I use the string? Item prototype name?
Yes.
If you want to get ahold of me I'm almost always on Discord.

User avatar
kumpu
Fast Inserter
Fast Inserter
Posts: 111
Joined: Wed Jun 07, 2017 10:10 am
Contact:

Re: Bug when trying to set burner.currently_burning

Post 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...

User avatar
kumpu
Fast Inserter
Fast Inserter
Posts: 111
Joined: Wed Jun 07, 2017 10:10 am
Contact:

Re: Bug when trying to set burner.currently_burning

Post 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.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13209
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Bug when trying to set burner.currently_burning

Post 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.
If you want to get ahold of me I'm almost always on Discord.

User avatar
kumpu
Fast Inserter
Fast Inserter
Posts: 111
Joined: Wed Jun 07, 2017 10:10 am
Contact:

Re: Bug when trying to set burner.currently_burning

Post 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...

Rseding91
Factorio Staff
Factorio Staff
Posts: 13209
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Bug when trying to set burner.currently_burning

Post by Rseding91 »

A small thing: "fuelItemStack.prototype.name" can just be "fuelItemStack.name"
If you want to get ahold of me I'm almost always on Discord.

User avatar
kumpu
Fast Inserter
Fast Inserter
Posts: 111
Joined: Wed Jun 07, 2017 10:10 am
Contact:

Re: Bug when trying to set burner.currently_burning

Post by kumpu »

Rseding91 wrote:A small thing: "fuelItemStack.prototype.name" can just be "fuelItemStack.name"
Right, thanks 8-)

Post Reply

Return to “Resolved Problems and Bugs”