ethanwdp Posted July 13, 2015 Share Posted July 13, 2015 I've hit a snag with my Cheat Core mod, the global functions are truly global -- they are accessible to ANY mod, and the functions would be overwritten by a modified Cheat Core in another mod. This is a problem, because that was supposed to be a modders resource - filled with tons of useful functions you can call, and flexible enough to be modified for your own need. Problem is, if more than one mod that's loaded uses Cheat Core, they'll conflict with eachother and be overwritten. As far as I know, locals are only accessible to one function or lua file (depending on where you put it). Globals are truly global and overwrite eachother. So how do I make a function or variable only available to lua files in the same directory? Link to comment Share on other sites More sharing options...
RoboMat Posted July 13, 2015 Share Posted July 13, 2015 I've hit a snag with my Cheat Core mod, the global functions are truly global -- they are accessible to ANY mod, and the functions would be overwritten by a modified Cheat Core in another mod. That's what globals are for. Usually one would try to avoid the usage of globals at all by dividing stuff into modules, but that would require a "require" function which actually returns the file, but that doesn't seem to work in Kahlua (or at least not in PZ). You might be able to use some metatable hack, since all globals are stored in _G. But I do not recommend that. In my humble opinion it is not your job to make sure mods don't conflict with each other. If you provide a library and modders use it, all you have to do is make sure that your own functions work fine. If a modder wants to modify a function from your library he shouldn't override it or change the public interface of your library. What I want to say is, that it is the modders responsibility to make sure his mods don't cause conflicts with other mods. Link to comment Share on other sites More sharing options...
ethanwdp Posted July 13, 2015 Author Share Posted July 13, 2015 I've hit a snag with my Cheat Core mod, the global functions are truly global -- they are accessible to ANY mod, and the functions would be overwritten by a modified Cheat Core in another mod.That's what globals are for. Usually one would try to avoid the usage of globals at all by dividing stuff into modules, but that would require a "require" function which actually returns the file, but that doesn't seem to work in Kahlua (or at least not in PZ).You might be able to use some metatable hack, since all globals are stored in _G. But I do not recommend that.In my humble opinion it is not your job to make sure mods don't conflict with each other. If you provide a library and modders use it, that's fine. If a modder wants to modify a function from your library he shouldn't override it. So it is the modders responsibility to make sure he doesn't cause conflicts with other mods.If you take a look at my old modding utilities, a lot of people just copied the functions into their own code to modify it.The other thing is that I want to provide people with a hassle free experience with my mods, even if it's just a library of functions for modders. Convenience is key for me. I know it's not my job to prevent conflicts with other mods using Cheat Core, but I still would like to make things easier for the modder and the user without being invasive. Anyways, I'll try out the require function. I forgot that was even a thing Link to comment Share on other sites More sharing options...
RoboMat Posted July 13, 2015 Share Posted July 13, 2015 The other thing is that I want to provide people with a hassle free experience with my mods, even if it's just a library of functions for modders.It seems like I don't understand what you are trying to do.library.yourFunction(foo);That's all a modder should have to do How do you want to make it more convenient than that? Link to comment Share on other sites More sharing options...
ethanwdp Posted July 13, 2015 Author Share Posted July 13, 2015 The other thing is that I want to provide people with a hassle free experience with my mods, even if it's just a library of functions for modders.It seems like I don't understand what you are trying to do.library.yourFunction(foo);That's all a modder should have to do How do you want to make it more convenient than that? Yes, but if a mod is running an older version of Cheat Core that would be missing some functions and variables, it'll potentially overwrite other mods running Cheat Core. I don't want the modder to drop everything and quickly release a hotfix for every time I release a new update for Cheat Core. If the functions were only accessible to lua files within the same directory, it'd avoid that issue. Link to comment Share on other sites More sharing options...
RoboMat Posted July 13, 2015 Share Posted July 13, 2015 Is your library a mod which needs to be loaded by PZ or do modders copy the files in their own projects? Link to comment Share on other sites More sharing options...
ethanwdp Posted July 13, 2015 Author Share Posted July 13, 2015 Is your library a mod which needs to be loaded by PZ or do modders copy the files in their own projects?Modders copy the file, cheatcore.lua, to their lua directory in their mod. Sorry about being vague about that, my bad. Link to comment Share on other sites More sharing options...
RoboMat Posted July 13, 2015 Share Posted July 13, 2015 Okay, NOW I understand what the problem is One way to fix this, is to simply append the version to the filename.E.g.:cheatcore_v121.luaIf you now release a new version you call it:cheatcore_v130.luaThis way it will not override the previous versions that any other mod might use since the game loads them as separate files. Link to comment Share on other sites More sharing options...
ethanwdp Posted July 13, 2015 Author Share Posted July 13, 2015 Okay, NOW I understand what the problem is One way to fix this, is to simply append the version to the filename.E.g.:cheatcore_v121.luaIf you now release a new version you call it:cheatcore_v130.luaThis way it will not override the previous versions that any other mod might use since the game loads them as separate files. Woo! That'll work, thanks! Link to comment Share on other sites More sharing options...
ethanwdp Posted July 16, 2015 Author Share Posted July 16, 2015 Hmm, didn't work. To test this, I put a print("TEST") under Cheat Menu's Cheat Core's HandleToggle function. Cheat Menu's Cheat Core file was renamed to CheatCoreForCheatMenu. Let Me Speak!, which also uses Cheat Core (but with a different file name), loaded the modified Handle Toggle function from Cheat Menu's Cheat Core. So this means that they're still overlapping... Link to comment Share on other sites More sharing options...
RoboMat Posted July 16, 2015 Share Posted July 16, 2015 Yes, you need to rename the global table too. Link to comment Share on other sites More sharing options...
ethanwdp Posted July 16, 2015 Author Share Posted July 16, 2015 Yes, you need to rename the global table too.That's what I was trying to avoid... Guess there's no other way, then. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now