Detecting Code Reload?
FocusedWolf
Join Date: 2005-01-09 Member: 34258Members
in Modding
Does anyone have any suggestions for a way to detect a "Recreating class 'className'" event, which occurs when you save changes to a lua file while ns2 is running.
Here's <a href="http://pastebin.com/rv2fQyCK" target="_blank">code</a> for how i'm dealing with this currently.
Here's <a href="http://pastebin.com/rv2fQyCK" target="_blank">code</a> for how i'm dealing with this currently.
Comments
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->local function OnReload()
// Do whatever
end
OnReload()<!--c2--></div><!--ec2-->
Warning to people, reloading from file changes (hotloading of lua files) can be hit or miss depending on what you're doing (usually though i think it's possible to get it working to the point of being good enough to try your changes without needing to restart NS2.... I have a way that sort of works for my mod... it's kind of complicated (no it's not what i show in post #1), so let me know if your desperate enough to want it... it's not perfect).
Here's an advanced example where, to put it bluntly, Max's suggestion will not work: <a href="http://www.gamefront.com/files/service/thankyou?id=20679356" target="_blank">http://www.gamefront.com/files/service/thankyou?id=20679356</a>
An example of were you can get away with no "reload" code (just a reload procedure) would be if you modding something like GUIMarineHUD.lua (marine user interface that shows when you join the marine team). When doing changes which affects this, the game will spew errors until you rr to the readyroom and j1. What's happening is the class is being destructed and recreated (think of it as manual reload of hotloaded class).