Page 1 of 1
[16.22] Desync in scenario
Posted: Sat Feb 03, 2018 9:09 pm
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 (441.14 KiB) Viewed 1686 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
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
Re: [16.22] Desync in scenario
Posted: Sat Feb 03, 2018 9:39 pm
by posila
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.
Re: [16.22] Desync in scenario
Posted: Sat Feb 03, 2018 11:11 pm
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

Re: [16.22] Desync in scenario
Posted: Sat Feb 03, 2018 11:27 pm
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.
Re: [16.22] Desync in scenario
Posted: Sun Feb 04, 2018 4:41 pm
by WIZ4
This solved my problem, thank you:)