Machiavelli24
Mod creator
- Joined
- May 9, 2012
- Messages
- 818
I have some lua code that I want to be able to copy into multiple different mods. However, I only want the code to execute once even when multiple mods containing the code are active.
For example, say I have a lua function (EveryTurnThing) that is added to GameEvents.PlayerDoTurn. Mod A contains EveryTurnThing.lua and Mod B also contains EveryTurnThing.lua. If an end-user is playing with both Mod A and Mod B than EveryTurnThing will fire twice ever GameEvents.PlayerDoTurn. I want to make it fire only once.
Things I've tried that didn't work
1) Only adding if GameEvents.PlayerDoTurn.Count(EveryTurnThing) is 0.
2) Doing GameEvents.PlayerDoTurn.Remove(EveryTurnThing) before adding.
3) Setting VFS to true (the files are still loaded multiple times even if they all overwrite eachother)
4) Creating an "IsInitialized" variable in the database (using InsertOrAbort) and then updating the value with DB.Query("UPDATE stuff...). The Query didn't change the value even though I put it in an empty for loop.
For example, say I have a lua function (EveryTurnThing) that is added to GameEvents.PlayerDoTurn. Mod A contains EveryTurnThing.lua and Mod B also contains EveryTurnThing.lua. If an end-user is playing with both Mod A and Mod B than EveryTurnThing will fire twice ever GameEvents.PlayerDoTurn. I want to make it fire only once.
Things I've tried that didn't work
1) Only adding if GameEvents.PlayerDoTurn.Count(EveryTurnThing) is 0.
2) Doing GameEvents.PlayerDoTurn.Remove(EveryTurnThing) before adding.
3) Setting VFS to true (the files are still loaded multiple times even if they all overwrite eachother)
4) Creating an "IsInitialized" variable in the database (using InsertOrAbort) and then updating the value with DB.Query("UPDATE stuff...). The Query didn't change the value even though I put it in an empty for loop.