Keeping Mod deterministic

Place to get help with not working mods / modding interface.
reaperrar
Burner Inserter
Burner Inserter
Posts: 16
Joined: Mon Mar 14, 2016 5:47 am
Contact:

Keeping Mod deterministic

Post by reaperrar »

I've just started creating a mod and I'm wondering how we can keep things deterministic (common things to do/avoid) so they work flawlessly in multiplayer.

Also, I've done some research and have found things as simple as using floating point numbers will result in non-deterministic behaviours across simulations because of rounding logic differences. However, I've looked at the internals of some other mods and floating point number usage is common and seems to not result in a desync :/
Is it safe to do a simple interpolation between two integers, where the scalar value used to multiply is a floating point number?
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: Keeping Mod deterministic

Post by aubergine18 »

Rounding numbers issue should hopefully be resolved since 0.14.10 - if not please report issues in bug reporting forum so the devs know.

Other than that, see http://lua-api.factorio.com/latest/Data-Lifecycle.html
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
reaperrar
Burner Inserter
Burner Inserter
Posts: 16
Joined: Mon Mar 14, 2016 5:47 am
Contact:

Re: Keeping Mod deterministic

Post by reaperrar »

aubergine18 wrote:Rounding numbers issue should hopefully be resolved since 0.14.10 - if not please report issues in bug reporting forum so the devs know.

Other than that, see http://lua-api.factorio.com/latest/Data-Lifecycle.html
I appreciate your response. However, I'm a little confused about the relevancy of the data lifecycle in respect to my opening questions. I can see that the mod load order is deterministic but not much else other than that.

Also, rounding issues are still present in the current version (13.20)? So it is not safe to use floating point numbers currently?
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: Keeping Mod deterministic

Post by aubergine18 »

If you're using old version of Factorio, like 0.13 branch, you will sill have those errors. I suggest upgrading to the 0.14 branch.

If you do need to work around the rounding errors in 0.13, take a look at this code: https://github.com/narc0tiq/evoGUI/blob ... tor.lua#L8

Another thing that sometimes causes desync is making local references to math functions, for example:

local round = math.round -- this can cause problems
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
reaperrar
Burner Inserter
Burner Inserter
Posts: 16
Joined: Mon Mar 14, 2016 5:47 am
Contact:

Re: Keeping Mod deterministic

Post by reaperrar »

aubergine18 wrote:If you're using old version of Factorio, like 0.13 branch, you will sill have those errors. I suggest upgrading to the 0.14 branch.

If you do need to work around the rounding errors in 0.13, take a look at this code: https://github.com/narc0tiq/evoGUI/blob ... tor.lua#L8

Another thing that sometimes causes desync is making local references to math functions, for example:

local round = math.round -- this can cause problems
Cheers, so fixed point math is required in place of float operations then it seems. Your example will help heaps.

On a side note, I'm obviously missing how to upgrade to 0.14 given current steam version is 13.20 (beta opt in needed or such?). Anyway, isn't i most safe when developing for the general public to dev for the current release?
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: Keeping Mod deterministic

Post by aubergine18 »

A lot of mods being uploaded to portal already require 0.14 branch as it fixes so many things with each new release.

To get 0.14 on steam, you'll need to opt in to beta releases via library > right click game in sidebar > properties.
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
reaperrar
Burner Inserter
Burner Inserter
Posts: 16
Joined: Mon Mar 14, 2016 5:47 am
Contact:

Re: Keeping Mod deterministic

Post by reaperrar »

aubergine18 wrote:A lot of mods being uploaded to portal already require 0.14 branch as it fixes so many things with each new release.

To get 0.14 on steam, you'll need to opt in to beta releases via library > right click game in sidebar > properties.
Well, that's fair enough. Unfortunately I'm paying for a service where I don't have access to update the server to opt into beta versions.

That aside, I'm still not understanding how other popular mods (requiring version 0.13) which don't implement any fixed point math are desync free when they are clearly using floating point numbers.
Post Reply

Return to “Modding help”