[Rseding91|RESOLVED|0.16.2] fluidbox not writable

This subforum contains all the issues which we already resolved.
User avatar
steinio
Smart Inserter
Smart Inserter
Posts: 2638
Joined: Sat Mar 12, 2016 4:19 pm
Contact:

[Rseding91|RESOLVED|0.16.2] fluidbox not writable

Post by steinio »

Hi,

i'm not sure if this is a bug or just my lag of programming lua.

I used the fluidbox example from here: http://lua-api.factorio.com/latest/LuaFluidBox.html but at adding the fluid table i get this error:

Code: Select all

Error while running event StoneWaterWell::on_tick (ID 0)
__StoneWaterWell__/control.lua:20: bad argument #-1 to '__newindex' (string expected, got nil)
Code:

Code: Select all

				amount 	= 0
				fluid	= iwaterwell.fluidbox[1] or {}

				if fluid ~= nil then
					amount = fluid.amount
				end
				
				fluid.type = "water"
				fluid.amount = amount
				fluid.temperature = 10
				iwaterwell.fluidbox[1] = fluid
#iwaterwell.fluidbox returns 1

The attached mod is another version as added in my other thread.

Greetings, steinio.
Attachments
StoneWaterWell_1.0.5.zip
(260.42 KiB) Downloaded 85 times
Last edited by steinio on Thu Dec 14, 2017 8:05 pm, edited 1 time in total.
Image

Transport Belt Repair Man

View unread Posts
User avatar
Mylon
Filter Inserter
Filter Inserter
Posts: 525
Joined: Sun Oct 23, 2016 11:42 pm
Contact:

Re: [0.16.2] fluidbox not writable

Post by Mylon »

You're trying to assign the fluidbox (a reference object) to a lua table.

You're already editing the individual fluidbox properties, so simply commenting out the last line ( iwaterwell.fluidbox[1] = fluid ) should fix your script.
User avatar
steinio
Smart Inserter
Smart Inserter
Posts: 2638
Joined: Sat Mar 12, 2016 4:19 pm
Contact:

Re: [0.16.2] fluidbox not writable

Post by steinio »

Well i commented it out and it don't crashes anymore.
But also the tank amount is not changed.

In the APi documentation it's explicitly written, that the values need to be rewritten in the fluidbox.

If the fb is empty you get a nil, what itry to catch with 'or {}'

Problem is, the original code worked in 0.15 and there are no documented changes to fluidboxes - so i don*t get it.
Image

Transport Belt Repair Man

View unread Posts
User avatar
Mylon
Filter Inserter
Filter Inserter
Posts: 525
Joined: Sun Oct 23, 2016 11:42 pm
Contact:

Re: [0.16.2] fluidbox not writable

Post by Mylon »

Oh, apparently that is how fluids work. Try using this code:

Code: Select all

amount    = 10
            fluid   = iwaterwell.fluidbox[1] or {}

            if fluid ~= nil then
               amount = fluid.amount
           
              fluid.type = "water"
              fluid.amount = amount
              fluid.temperature = 10
              iwaterwell.fluidbox[1] = fluid
            end
If you want to set amount to 0, then simply do

Code: Select all

iwaterwell.fluidbox[1] = nil
quyxkh
Smart Inserter
Smart Inserter
Posts: 1031
Joined: Sun May 08, 2016 9:01 am
Contact:

Re: [0.16.2] fluidbox not writable

Post by quyxkh »

It's not "type" any more, it's "name" now.
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5304
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: [0.16.2] fluidbox not writable

Post by Klonan »

quyxkh wrote:It's not "type" any more, it's "name" now.
Correct, its now 'name', not 'type'

Also not a bug
User avatar
steinio
Smart Inserter
Smart Inserter
Posts: 2638
Joined: Sat Mar 12, 2016 4:19 pm
Contact:

Re: [0.16.2] fluidbox not writable

Post by steinio »

Klonan wrote:
quyxkh wrote:It's not "type" any more, it's "name" now.
Correct, its now 'name', not 'type'

Also not a bug
Where should i know it from if the API doc is not updated.
fluid.PNG
fluid.PNG (100.28 KiB) Viewed 2132 times
Changed the old code accordingly and it works now.
Image

Transport Belt Repair Man

View unread Posts
Rseding91
Factorio Staff
Factorio Staff
Posts: 14598
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [NaB|RESOLVED|0.16.2] fluidbox not writable

Post by Rseding91 »

Thanks for pointing that out. I've updated the lua docs for the next version of 0.16.
If you want to get ahold of me I'm almost always on Discord.
Post Reply

Return to “Resolved Problems and Bugs”