Lua API global Variable Viewer (gvv)

by Ritn

This is a debugging tool. This mod adds commands /gvv and others and a hotkey(Ctrl+Shift+V) to allow you to check _G and global table of map or each mods. Only admins can use command if it is multiplay game. You have to input some code for temporary accessibility or have to edit "control.lua" of other mod or map to access global table of the mod or map. See "Helper" tab for instructions.

Utilities
8 days ago
1.0 - 2.0
3.14K

b Desynchronization with mod: RitnTeleportation

3 years ago

Hi,
I frequently use your mod to monitor the global data of my mod but this one creates server desynchronizations.
This problem persists since the first version of your mod.

The desynchronization problem is often linked to local variables which change state in the player but do not change state on the server or vice versa and the server sees the non-synchronization between the two and disconnects the player.

When this happens:
Every time I refresh the global data linked to a player.

I have a whole data structure that changes when:
- a player comes into play.
- a player places a portal.
- a player places a teleporter.
- a player uses a portal to join another player's map.

Here are some screenshots to see what it looks like:
https://ibb.co/tz9DDqQ
https://ibb.co/FY2f1vf

3 years ago
(updated 3 years ago)

I took a look into global table of your RitnTeleportation mod via gvv GUI. (I didn't see your source code yet)
I found you used a variable in _G table as "variable can be changed during runtime", which is "_G.connected_players".

Using "_G" table for runtime variable space is NOT RECOMMENDED, I recommend you leave _G space modifiable only during lua file loading stage and "on_load, on_init, on_configuration_changed" event stage.
Use _G table as similar way to "constants", not "variables"
Reason why is that "_G" is not saved in savefile.
Only "global" is saved. New player always download "savefile" from host. Because of this, variables in _G changed during runtime can cause desync for new players.
Please see official documentation about global variables.
https://lua-api.factorio.com/latest/Global.html

"_G" is the another global variable space which saves your variables declared without "local " notation in front of line.

Try to move "connected_players" to somewhere under the "global" table object.
And then test again please.

You also can see your variable via command
/c __RitnTeleportation__ game.print(_G.connected_players)
or
/c __RitnTeleportation__ game.print(connected_players)
both commands are equivalent.

3 years ago

Hi,
I updated my mod by passing the variables to "_G".
The one that remains is either functions or constants.
I still had a case of desynchronization.
In any case, thank you for having warned me of this error (an oversight on my part).

New response