Desync from my scenario.

Place to get help with not working mods / modding interface.
Post Reply
yagaodirac
Fast Inserter
Fast Inserter
Posts: 152
Joined: Sun Jun 16, 2019 4:04 pm
Contact:

Desync from my scenario.

Post by yagaodirac »

I made a scenario. The script in this scenario modifies the amount of ore entities every 5 seconds. I works perfect on my own pc when I debug. But when I deploy it on a server and link to it from my Factorio started from Steam, the desync occurs.
Besides, when it's server and clients, none of us has seen the amount of any ore entities has ever changed, which is supposed to change every 5 seconds.
Any idea? Should I remove the ore entity and recreate one with new amount assigned directly?

Does the file uploading work?

I think I know the problem. When I assign a new amount value to an ore entity, the game doesn't sync the data. So when any critical event based on the amount happens, the server and my client don't match. The solution is something you've done to the fluidbox. The api looks like add_liquid, remove_liquid. So, please add the add_amount and remove_amount functions to ore entity, and sync when they are called.

Also, the energy, the progressions for assembly machine. If you don't want people to modify them in script, make them read only, or these details make tons of desync.

User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 2250
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: Desync from my scenario.

Post by boskid »

What is this bug report about?

All of it sounds like you are trying to keep some state in a non-serialised variable (outside of "global" variable) and you are surprised when the desync happens because the variable was not serialised.

Last part of your message about energy and assembling machine progress is just wrong. They are part of the game state and can be mutated without risk of a desync. If there are desyncs then your scripting is broken. There is no point in any further discussion without seeing your script.

Moving to Modding help.

yagaodirac
Fast Inserter
Fast Inserter
Posts: 152
Joined: Sun Jun 16, 2019 4:04 pm
Contact:

Re: Desync from my scenario.

Post by yagaodirac »

boskid wrote:
Sat Apr 17, 2021 6:05 am
The upload feature doesn't work at all. So you don't see anything.
https://mods.factorio.com/mod/OreBeach
Literally, host it in a server, link to it, and you are gonna see what I encountered.

I guess your suggestion is using the global variable to store data because all the data inside that table is synced.

User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 2250
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: Desync from my scenario.

Post by boskid »

Not looking too far, line 18:

Code: Select all

new_source_to_create = 50
This variable is stored in the non-serialized part of the script context. That means if there are some chunks generated, player who was in the game when chunk was generated will have that value increased by 0.1 (line 26) but when a game is saved this variable is ignored (its not "global.new_source_to_create") and when a new player joins, for the joining player the control.lua is executed from the beginning and that player will get new_source_to_create of 50. This is already a script desync. Trying to `game.print(new_source_to_create)` at this point will already throw a desync because server will print "50.1" and a client will print "50".

As this variable is not saved, using it in (line 354)

Code: Select all

for i=1,new_source_to_create do
and creating entities based on it will desync just because server may create different amount of entities than a client.

yagaodirac
Fast Inserter
Fast Inserter
Posts: 152
Joined: Sun Jun 16, 2019 4:04 pm
Contact:

Re: Desync from my scenario.

Post by yagaodirac »

boskid wrote:
Sun Apr 18, 2021 7:38 am
OK, thanks a lot. Now I know why the very famous scenario( such as Mnt fortress) stores most of the data in a "global" variable.
You should write more info about this desync error in the document. I saw the doc-html/Global.html but didn't guess that deeply.
Now I know, If all the mutable variables are moved under the global variable, my trouble is probably gone.

One more time, thanks a lot, and, you should have written more detail in the docs.

Post Reply

Return to “Modding help”