Event handlers de-sync

Place to get help with not working mods / modding interface.
Post Reply
User avatar
Giovy2001
Manual Inserter
Manual Inserter
Posts: 2
Joined: Mon Aug 01, 2022 1:40 pm
Contact:

Event handlers de-sync

Post by Giovy2001 »

Hello, I'm making a mod called "Dialogue box" which allows modder to create dialogues quickly.
briefly you just define a global variable containing all necessary info and the mods add dialogues for you.

Example:
example_dialogue_1 = {
person="Uncle", -- Used in the title of the dialogue and as a "id" for the image to display
active=true, -- Set to true to be used as trigger-dialogue, Set to false to be displayed only in the logs (if false trigger and condition has no effect)
trigger=defines.events.on_cutscene_cancelled, -- trigger LuaEvent
condition="always_true", -- Name of the function defined in the remote interface
caption="This is a custom dialogue.\nJust want to say hi!"}, -- dialogue caption
}

Result:
Image

The mod works fine in singleplayer, but it's getting me a headache in multiplayer.
It's not possibile to join a game if the event handlers are different.
My mod calls them when the game is fully loaded (because they are set from an interface)
The problem is that the player joining wont have those events handler active until the game is fully loaded which cant happen because he will desync.

I tried to:
- Init event handlers before, but I didn't find a way that doesn't include writing dialogues on the same mod (which is not what I'm aiming at)
- Detect if a player is joining in order to remove handlers and re-init them after. I don't think there is a way to do that.
- I made a button to manually toggle event handlers, but the only way that I found to fully remove them is by reloading the game.

It's a bit annoying to manually turn off triggers, save the game, reload, wait for the player to join and then turning triggers back on.
I was hoping someone has some magic tricks to share. Thanks for any help <3
Attachments
dialogue-box_1.0.0.zip
This is the zipped mod, it's also on the modportal
(1.7 MiB) Downloaded 34 times

Hornwitser
Fast Inserter
Fast Inserter
Posts: 205
Joined: Fri Oct 05, 2018 4:34 pm
Contact:

Re: Event handlers de-sync

Post by Hornwitser »

The way you usually deal with event handlers registered at runtime is to store all the related state that made you register them into the global table, and then re-register all of the handlers again in the on_load event based on the state you stored in global.

User avatar
Giovy2001
Manual Inserter
Manual Inserter
Posts: 2
Joined: Mon Aug 01, 2022 1:40 pm
Contact:

Re: Event handlers de-sync

Post by Giovy2001 »

Hornwitser wrote:
Mon Aug 01, 2022 8:18 pm
The way you usually deal with event handlers registered at runtime is to store all the related state that made you register them into the global table, and then re-register all of the handlers again in the on_load event based on the state you stored in global.
Thank you. It was simpler than I thought.
The way I uploaded the dialogues was a mess. Fixing the loading event was enough to make it work properly.

Post Reply

Return to “Modding help”