Page 1 of 1

[Rseding91|RESOLVED|0.16.2] fluidbox not writable

Posted: Thu Dec 14, 2017 3:43 pm
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.

Re: [0.16.2] fluidbox not writable

Posted: Thu Dec 14, 2017 3:50 pm
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.

Re: [0.16.2] fluidbox not writable

Posted: Thu Dec 14, 2017 4:09 pm
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.

Re: [0.16.2] fluidbox not writable

Posted: Thu Dec 14, 2017 4:26 pm
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

Re: [0.16.2] fluidbox not writable

Posted: Thu Dec 14, 2017 5:07 pm
by quyxkh
It's not "type" any more, it's "name" now.

Re: [0.16.2] fluidbox not writable

Posted: Thu Dec 14, 2017 5:11 pm
by Klonan
quyxkh wrote:It's not "type" any more, it's "name" now.
Correct, its now 'name', not 'type'

Also not a bug

Re: [0.16.2] fluidbox not writable

Posted: Thu Dec 14, 2017 8:04 pm
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 2135 times
Changed the old code accordingly and it works now.

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

Posted: Thu Dec 14, 2017 8:09 pm
by Rseding91
Thanks for pointing that out. I've updated the lua docs for the next version of 0.16.