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?
Keeping Mod deterministic
- aubergine18
- Smart Inserter
- Posts: 1264
- Joined: Fri Jul 22, 2016 8:51 pm
- Contact:
Re: Keeping Mod deterministic
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
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.
Re: Keeping Mod deterministic
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.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
Also, rounding issues are still present in the current version (13.20)? So it is not safe to use floating point numbers currently?
- aubergine18
- Smart Inserter
- Posts: 1264
- Joined: Fri Jul 22, 2016 8:51 pm
- Contact:
Re: Keeping Mod deterministic
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
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.
Re: Keeping Mod deterministic
Cheers, so fixed point math is required in place of float operations then it seems. Your example will help heaps.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
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?
- aubergine18
- Smart Inserter
- Posts: 1264
- Joined: Fri Jul 22, 2016 8:51 pm
- Contact:
Re: Keeping Mod deterministic
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.
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.
Re: Keeping Mod deterministic
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.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.
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.