Maris Posted April 29, 2015 Share Posted April 29, 2015 For example, I have some wrong code:v = SpawnPrefab("twigs")I forgot to write "GLOBAL." so this will cause a crash. Is there any way to fix the mod using only console? There are many people on the server. All I need is add some variable to the mod's name space:SpawnPrefab = GLOBAL.SpawnPrefabIs it possible? Link to comment https://forums.kleientertainment.com/forums/topic/53336-how-to-fix-the-mod-without-restarting-the-server/ Share on other sites More sharing options...
DarkXero Posted April 29, 2015 Share Posted April 29, 2015 To my surprise:ModManager:GetMod("modname").env.SpawnPrefab = SpawnPrefabwould work. That is, if your SpawnPrefab is inside a function, or a DoTaskInTime, or a DoPeriodicTask (that means the GLOBAL gets checked and assigned on every function run, so the value loads itself in other times beyond the mod loading). Link to comment https://forums.kleientertainment.com/forums/topic/53336-how-to-fix-the-mod-without-restarting-the-server/#findComment-633116 Share on other sites More sharing options...
Developer PeterA Posted April 29, 2015 Developer Share Posted April 29, 2015 Another possibility would be to look at the functionality in DoReload() in reload.lua. I don't know if anyone has ever used it for reloading mod lua files, so there may be some "quirks". But if you simply just need to drop some variables into your mod's environment, @DarkXero's method should work just fine. Link to comment https://forums.kleientertainment.com/forums/topic/53336-how-to-fix-the-mod-without-restarting-the-server/#findComment-633161 Share on other sites More sharing options...
DarkXero Posted April 29, 2015 Share Posted April 29, 2015 @PeterA, now that you mentioned this, I tried using it. My first issue is that modmain is basically unreachable doing hotswap("modmain").It went through all the scripts folders, in all my mods, and the game scripts folder.I would have to edit the custom loader or copy the functionality of reload outside it. Then I tried to make functions in modmain depend on values outside it. For example, I make a global table, and there I store all values and functions I will use in modmain, then I write the modmain using the table values. I use files in scripts to load these values, so when I hotswap them, if I changed any values, the table would have the new values. Well, I got functions getting executed many times and some values not getting replaced correctly (although in some cases it worked!). I presume hotswapping modmains will have the many function executions effect: I didn't remove the postinit of an AddPrefabPostInit, and reloading the file would cause to add yet another postinit, not replace it. Overall, I would say not worth the trouble.If you have to unload and load the mod for changes to be correct then you may as well restart the server. Link to comment https://forums.kleientertainment.com/forums/topic/53336-how-to-fix-the-mod-without-restarting-the-server/#findComment-633264 Share on other sites More sharing options...
Developer PeterA Posted April 30, 2015 Developer Share Posted April 30, 2015 @DarkXero, thanks for reporting back on your findings! Link to comment https://forums.kleientertainment.com/forums/topic/53336-how-to-fix-the-mod-without-restarting-the-server/#findComment-633281 Share on other sites More sharing options...
Maris Posted April 30, 2015 Author Share Posted April 30, 2015 (edited) There are various relations and hooks like this:fn_enabled = truecomp = require "components/comp"old_fn = comp.fnnew_fn = function(...) if fn_enabled then -- -> custom code end return old_fn(self,...)endcomp.fn = new_fnetc. So we need some function for unloading mod and clearing all that stuff. For example:ModOnRemove = function() if comp.fn == new_fn then comp.fn = old_fn else fn_enabled = false endendGenerally it isn't so necessary. Therefore it is possible to concentrate on more important things. And I will use this:ModManager:GetMod("modname").env.SpawnPrefab = SpawnPrefabThank DarkXero for neat solution. Edited April 30, 2015 by Maris Link to comment https://forums.kleientertainment.com/forums/topic/53336-how-to-fix-the-mod-without-restarting-the-server/#findComment-633353 Share on other sites More sharing options...
DarkXero Posted April 30, 2015 Share Posted April 30, 2015 @Maris, yes Maris, that's basically what the hotswap in reload.lua does. It works to switch values that a mod constantly reloads, or functions that get constantly executed. The downside to doing that is that some functions can't get unexecuted, and provoke permanent changes until quitting and reloading, so you end up executing a function with errors and in top of that, another one with the corrected data. A mess. Link to comment https://forums.kleientertainment.com/forums/topic/53336-how-to-fix-the-mod-without-restarting-the-server/#findComment-633415 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