[16.22] Desync in scenario

Bugs that are actually features.
User avatar
WIZ4
Fast Inserter
Fast Inserter
Posts: 209
Joined: Thu Apr 07, 2016 1:36 pm
Contact:

[16.22] Desync in scenario

Post by WIZ4 »

Hi devs! I wrote a scenario that spawns in a random place some number of nests of spawners, worms, turrets and artillery It will spawn with an interval of one hour:
8l2CBzdr7BU.jpg
8l2CBzdr7BU.jpg (441.14 KiB) Viewed 1643 times
In a single game it feels good, but in multiplayer begins desync for all players. At the time when this nest is generated.
I attached the save in which the spawner should appear in a minute. You can also use this function to pop the spawners immediately

Code: Select all

/c spawners()
save: https://www.dropbox.com/s/0h5hcyzxs2i8h ... 2.zip?dl=0
desync: https://www.dropbox.com/s/3akv3k005dubs ... 4.zip?dl=0
scenario: https://www.dropbox.com/s/r7hpthi410cyk ... y.zip?dl=0
I understand that the code is written very strange, I'm inexperienced in this case.
And sorry for my google tranlate
My native language is russian. Sorry if my messages are difficult to read.
posila
Former Staff
Former Staff
Posts: 5448
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: [16.22] Desync in scenario

Post by posila »

Code: Select all

_G.count = 25
This line is causing the desyncs. First of all, Lua global variables are not serialized to save, only global table called "global" is. You need to write

Code: Select all

global.count = 25 -- this is equivalent of _G["global"].count = 25; or _G.global.count = 25
The second, if you initialize global variable this way, it will be reinitialized for anyone who joins the multiplayer. You need to initialize your global in on_init event.
[code]
script.on_init(function()
global.count = 25
end)
[/code]


Please refer to Modding help section of the forum for further help with your modding/scenario making endevours.
Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: [16.22] Desync in scenario

Post by Nexela »

posila wrote: The second, if you initialize global variable this way, it will be reinitialized for anyone who joins the multiplayer. You need to initialize your global in on_init event.

Assuming "if you initilize global variable this way" means from your example _G.global[v] = blah

in multiplayer declaring it the top of the file (outside of events) will have no real ill effects if you understand what is going on.

in on_init global is global is global
in on_load global is created/overwritten by global saved in map.

For example (outside of events)
global.a = "a"
save
global.a = "new a"
global.b = "b"
load

print(global.a) prints "a"
print(global.b) prints nil

The real issue not related to OP is there is no easy way to trigger an on_configuration_changed event for scenarios

However as stated on_init is the "correct" way to do it. and I am all for not allowing read/write access to global outside of events :)
posila
Former Staff
Former Staff
Posts: 5448
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: [16.22] Desync in scenario

Post by posila »

Nexela wrote:
posila wrote: The second, if you initialize global variable this way, it will be reinitialized for anyone who joins the multiplayer. You need to initialize your global in on_init event.

Assuming "if you initilize global variable this way" means from your example _G.global[v] = blah

in multiplayer declaring it the top of the file (outside of events) will have no real ill effects if you understand what is going on.
Ah, I guess you are right. I suppose it runs control.lua first and deserializes global second. That makes sense, thanks for correction.
User avatar
WIZ4
Fast Inserter
Fast Inserter
Posts: 209
Joined: Thu Apr 07, 2016 1:36 pm
Contact:

Re: [16.22] Desync in scenario

Post by WIZ4 »

This solved my problem, thank you:)
My native language is russian. Sorry if my messages are difficult to read.
Post Reply

Return to “Not a bug”