Desync when teleporing ore entities

Place to get help with not working mods / modding interface.
Post Reply
Mengmoshu
Long Handed Inserter
Long Handed Inserter
Posts: 53
Joined: Tue May 26, 2015 11:24 pm
Contact:

Desync when teleporing ore entities

Post by Mengmoshu »

My (attached) mod works fine in single player, it moves the ore where I expect it to when I expect it to. When I fire up a 2 player game with a friend the ore only moves on my screen regardless of who placed my machine, and eventually we desync, usually after interacting with moved ore or the place it is/was.

I'm using entity.teleport() around line 76 of control.lua. The other possibility that occurs to me is that I'm doing something wrong when I subscribe to a couple events around line 10.

Any advice on how to be more multiplayer friendly is welcome, even just general rules of thumb or links to guides.
Attachments
Resource_Relocation_Machine_0.0.1.zip
(27.84 KiB) Downloaded 50 times

Rseding91
Factorio Staff
Factorio Staff
Posts: 13346
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Desync when teleporing ore entities

Post by Rseding91 »

You're subscribing to 2 event handlers in the on_load event unconditionally which means that anyone loading into an existing game will subscribe to them while the first player who created the map will not have them subscribed.

It looks like you don't understand how event handlers work and when you should subscribe to them.
If you want to get ahold of me I'm almost always on Discord.

Mengmoshu
Long Handed Inserter
Long Handed Inserter
Posts: 53
Joined: Tue May 26, 2015 11:24 pm
Contact:

Re: Desync when teleporing ore entities

Post by Mengmoshu »

Ah. You're right that I don't understand event handlers, I'll have to study up on them. I put them where they're at in a fit of awkward bug hunting, and I only understood them well enough to borrow them from the mod I was using for reference (Item Collectors).

Do I just move them outside any other code blocks like they were in Item Collectors? And does that have any implications for using it on maps created before my mod was installed?

And thanks for pointing me at the broken bit of code. I don't have much coding experience and most of that has been with Visual Studio and the ability to step through with a debugger.

edit: And I realized right after posting that you wrote Item Collectors, Rseding. Thanks for the clear simple code to look at, and your use of the MIT license.

Post Reply

Return to “Modding help”