Closed Zinal001 closed 8 years ago
Thank you for reviewing the code; I am very much learning modding and lua as I go.
There are several problems (even in single player) with not using the global table. The most pressing is this: The overlays table maps the machines to their respective indicator light. This mapping is lost when saving, but all the indicator lights still hang around. The only way I have found so far to fix this is to explicitly remove them at load time. However, if I change all "overlays" to "global.overlays", I get the following error at load time:
Error while running deserialisation: [string "do local _={overlays={},freeze={}};local tabl..."]:1: too many local variables (limit is 200) in main function near '='
and I have yet to figure out what is going on there. Any ideas?
As for the 'nauvis' problem: I am not sure I have completely understood what other surfaces there are. All my games seem to only know of the single one. However, it is an easy fix, so I will add it to 0.0.4.
Well, the core game only has the surface nauvis but other mods can easily add other surfaces. I'll be honest, I've never seen that error before.. And I've been working with LUA for quite a while...
I'll do a fork and see if I can work it out..
It seems the cause of the error was that you were saving an entity directly into the global table.. Not sure why that's not possible, but I found a workaround by saving the positions of the entities instead of saving the entity itself..
You can checkout my heavily remade code here: https://github.com/Zinal001/Bottleneck/blob/master/control.lua
Great work! I will hopefully get some time to get this incorporated into the mod soon.
You can save entities directly in the global table. You just can't have more than 200~ something different values directly in the global table. Store the entities in a sub table and it will work fine.
It's simply a limit of Lua and the load-string method Lua has.
For instance:
global.my_entities = {entity1, entity2, entity3, ...} works just fine.
EDIT:
The issue is indeed storing the entities as keys in a table. You need to store them as values in the table and it works fine:
global.my_entities = {[1] = entity1, [2] = entity2, [3] = entity3}
Which you can insert into and remove from using table.insert() and table.remove()
If I take the 0.0.3 release, and replace all "overlays" with "global.overlays" I get the error mentioned above. Isn't that the same at the global.my_entities? I have done this in the "naiveglobal" branch.
I updated my comment, I misunderstood what was actually happening.
Ok, so it is indeed possible to save entities to the global table.. However, since the global table discards the meta-table information of the table, wouldn't that possible cause a desync upon loading a game?
Factorio handles meta tables for entities internally so you don't have to do anything with that.
Also virtually all objects gotten from the game engine can be saved in the global table.
Rseding91: Just don't use meta tables? Or re-create them on_load.
I thought all the lua objects from the game engine had meta tables.. Perhaps not.
Well, I'll go and change my fork again I guess.. No need to save the positions and search for the entities if it can just save the entity directly.
Factorio handles the saving and loading of the entity references and the associated meta tables.
Interesting. The wiki says:
Tables, but not metatables; tables with metatables become plain tables when saved/reloaded
Anyway.. Updated my fork to save the entities directly, no problem found with a factory with about 500 assembly machines + furnaces :smile: Code's here: https://github.com/Zinal001/Bottleneck/blob/master/control.lua
I updated the mod with your refactoriozation :) It passes the manual tests, but it is still a resource hog. I've given sampling a bit more thought, and have come to the conclusion that it has to be a lot more intelligent. Simply sampling once every N ticks won't work, since this might perfectly sync up with when the machine happens to be working, and thus not correctly identifying a bottleneck. I have a few ideas for how to remedy this, but it might be a couple of weeks before I get the time to do experiment with it.
Can you push the update over to mods.factorio.com? I just spent most of my day tracking down my MP desync issues to this mod (running 0.0.3).
Thanks!
Rseding91 their is one of your mods in factorio that I would really like to get its the landfill for Version 0.12.35 . I have been all over the net looking for it and have had no luck, any way you could find a way to get me a copy of it. I would greatly appreciate it.
First of all: This mod is a real life-saver! No more bottlenecks in my factory!
However, I've found a few things that might not work as expected:
overlays
,bounds
andfreeze
variables are not defined in theglobal
table.. This might cause de-syncs on multiplayer servers.nauvis
in all the functions. This will cause some problems with multi-surface mods (No assembly machines in other surfaces will be updated)Also, would it be possible to get the newest (0.0.3) version here as well?