Can someone explain what "client" executes on_events?

Place to get help with not working mods / modding interface.

Can someone explain what "client" executes on_events?

Postby AlienX » Fri May 19, 2017 10:01 am

Hi All,
I have a general question about how Factorio works with it's Lua Events (such as on_chunk_generated).

Task: Imagine 3 clients are connected to the game, there is a custom script inside the control.lua of the scenario file that re-rolls generated chunks to randomly spawn new entities, such as ore, or enemy bases, all 3 clients are connected to a headless client acting as the server.

Do all clients run the on_chunk_generated code at the same time?

If so, how does Factorio deal with entities that are randomly selected to be spawned or not?

Let's say that Client 1's random algorithm selected to spawn the entity, the headless client also did, but client 2 and 3's random algorithm selected not too - would this cause a desync due to 2 clients not having spawned the entity on their local map variant causing their map tick to have a different CRC than the rest?

The reason I ask this is because I believe that this is happening for me when new chunks are generated everyone desyncs - perhaps i just need to run the on_chunk_generated code on just a single client's game?
AlienX
Manual Inserter
Manual Inserter
 
Posts: 4
Joined: Wed May 17, 2017 7:13 pm

Re: Can someone explain what "client" executes on_events?

Postby darkfrei » Fri May 19, 2017 10:27 am

It's pseudo random, all clients have the same generator.
darkfrei
Filter Inserter
Filter Inserter
 
Posts: 312
Joined: Thu Nov 20, 2014 11:11 pm

Re: Can someone explain what "client" executes on_events?

Postby Nexela » Fri May 19, 2017 2:40 pm

The reason I ask this is because I believe that this is happening for me when new chunks are generated everyone desyncs - perhaps i just need to run the on_chunk_generated code on just a single client's game?

All clients have to run the exact same code at the exact same time and get the exact same result
Random is deterministicaly random for everyone :)

Feel free to post your code and someone will look at it. Are you saving variables correctly in the global table?
Nexela
Smart Inserter
Smart Inserter
 
Posts: 1477
Joined: Wed May 25, 2016 11:09 am

Re: Can someone explain what "client" executes on_events?

Postby DaveMcW » Fri May 19, 2017 11:51 pm

Yes, your problem is any variable that is not stored in global is not multiplayer-safe.
User avatar
DaveMcW
Smart Inserter
Smart Inserter
 
Posts: 1966
Joined: Tue May 13, 2014 11:06 am

Re: Can someone explain what "client" executes on_events?

Postby AlienX » Sat May 20, 2017 11:37 am

Alright that makes sense, thanks guys :)
AlienX
Manual Inserter
Manual Inserter
 
Posts: 4
Joined: Wed May 17, 2017 7:13 pm


Return to Modding help

Who is online

Users browsing this forum: No registered users and 5 guests