Bio Industries


Provides useful buildings and items, like the Bio Farm for growing trees. Solar Farm and Large Accumulator to make your electric setup easier. Bio Fuel section to produce organic plastic and batteries. Lots of New Wood Products, like the big electric pole, wooden pipes, dart turret. Plant trees using seedlings. Change terrain from deserts to grasslands using Fertilizer - helps trees grow better. And a lot more… Please visit the homepage on the forums for more information and feedback.

Content
9 months ago
0.14 - 1.1
54.4K
Manufacturing

b [Fixed?] control.lua:302: attempt to index local 'b' (a nil value)

3 years ago

MultiplayerManager failed: "The mod Bio Industries (1.1.9) caused a non-recoverable error.
Please report this error to the mod author.

Error while running event Bio_Industries::on_configuration_changed
Bio_Industries/control.lua:302: attempt to index local 'b' (a nil value)
stack traceback:
Bio_Industries/control.lua:302: in function <Bio_Industries/control.lua:302>
[C]: in function 'sort'
Bio_Industries/control.lua:302: in function 'handler'
stdlib/stdlib/event/event.lua:342: in function 'pcall'
stdlib/stdlib/event/event.lua:362: in function 'dispatch_event'
stdlib/stdlib/event/event.lua:438: in function 'dispatch'
stdlib/stdlib/event/event.lua:85: in function <stdlib/stdlib/event/event.lua:83>"

Pi-C
3 years ago

Interesting -- an error in table.sort()! I'd like to see how that can happen. Could you provide a saved game, please?

Pi-C
3 years ago

Thanks, I've figured it out! Immediately before sorting the table, I remove invalid entries from it, but the way I do it is wrong. I'll change that for the next version, but I'm still waiting for feedback regarding another bug. You can fix it locally, though. Just change line 295 in control.lua:

-- OLD (will leave a gap in the table):
tab[t] = nil 
-- NEW (no gap, entries after removed entry are moved down)
table.remove(tab, t)
3 years ago

On the server this is not possible, because then the synchronization does not work, so I have to wait unfortunately.
or I provide the patch and the users who do not install the patch manually have to wait. ;-) I think that should work for the moment.

Pi-C
3 years ago
(updated 3 years ago)

That will have to work for the time being! It seems there is a bug on the mod portal which causes that mod collaborators can't do anything that requires privileges -- changing thread titles, updating the info page, uploading a new release … Even if I wanted to (I'd rather wait until I can also fix the other bug I mentioned) I couldn't upload right now. :-(

3 years ago
(updated 3 years ago)

for t, tree in pairs(tab) do .... table.remove(tab, t)
you are sure that it works? you are in a for loop and changes the table which is looped through. the next element would be skipped because the table indices has been moved.
not tried in Lua just a thought. with C# I would have to adjust the for index or remove the item after the loop

That will have to work

I know, I didn't mean to push you with my thoughts.

Pi-C
3 years ago

for t, tree in pairs(tab) do .... table.remove(tab, t)
you are sure that it works? you are in a for loop and changes the table which is looped through. the next element would be skipped because the table indices has been moved.

Thanks for the hint, you're right. I guess that's why I used "tab[t] = nil" in the first place! I've just played around on my local Lua installation. Doing it recursively seems to work:

    tab = {43, 12, 23, 34, 45, 91, 7, 13, 4}

    f = function(tab, start)
      for i = start, #tab do
        if tab[i] and tab[i] % 2 == 0 then
          table.remove(tab, i)
          if f(tab, i) then
            return true
          end
        end
      end
      return true
    end

    f(tab, 1)

Calling that function will remove all even numbers from the table. If an entry has been removed, the function will be called again, starting at the last entry (which now has a new value). When the end of the table has been reached, the function will return true, which will cause the instance of the function that called it to finish as well. So there hardly is any overhead except for the entries that have been removed. Do you see anything wrong with that logic?

That will have to work

I know, I didn't mean to push you with my thoughts.

No problem, I was just explaining why I can't update…

3 years ago
(updated 3 years ago)

if yo you use a for (and not a for each) you don't need it recursive, you can remove the item and decrement the i variable
or reverse the for loop.

      for i = #tab, 1, -1  do
        if tab[i] and tab[i] % 2 == 0 then
         table.remove(tab, i)
        end
      end

but as already mentioned I am not a Lua expert

Pi-C
3 years ago

Removing + decrementing didn't work as expected, that's why I came up with the recursion. Basically, it's the same idea: remove the table entry, and start over again from the current position. Only the last recursion will reach the end of the table, and all previous recursions will immediately quit when that happens.

Reversing the loop should work as well, though, and is even easier to implement. Yes, I guess I'll go with this. :-)

Pi-C
3 years ago

Just updated. Please try 1.1.10! :-)

New response