arezu Posted February 27, 2012 Share Posted February 27, 2012 How do i "unload" functions and events I have loaded with loadstring? Link to comment
Kenix Posted February 27, 2012 Share Posted February 27, 2012 What you mean "unload" ? Can you show example? Link to comment
arezu Posted February 27, 2012 Author Share Posted February 27, 2012 I send client script to the player and then use loadstring to load the script, but i need to "unload" the script at another moment, without player having to reconnect. for example a map has disco sky, and then on next map i want to load the script for that map instead. Link to comment
BinSlayer1 Posted February 27, 2012 Share Posted February 27, 2012 Check this out http://www.lua.org/pil/8.html Assuming you have this: loadedFunc = loadstring('string here') loadedFunc() It doesn't actually say how to remove the loadstring, but I think you can try this: loadedFunc = nil Just check that link, maybe I missed it Link to comment
Kenix Posted February 27, 2012 Share Posted February 27, 2012 loadstring( 'g = 1' ) ( ) print( g ) -->1 g = nil print( g ) --> nil Link to comment
arezu Posted February 27, 2012 Author Share Posted February 27, 2012 I tried setting it to nil before, but it doesn't work. Link to comment
BinSlayer1 Posted February 27, 2012 Share Posted February 27, 2012 How can you tell it doesn't work? Stuff you pass to loadstring acts as compiling another separate (anonymous) function. When you call it, stuff(in it) gets executed. If you set the stuff that gets executed back to nil, then it should work fine (You can do so by using yet another loadstring if you want to) Link to comment
arezu Posted February 27, 2012 Author Share Posted February 27, 2012 outputDebugString("Script loaded!") fileLoaded[location] = loadstring(file[location]) fileLoaded[location]() setTimer(function(location) fileLoaded[location] = nil outputChatBox(tostring(fileLoaded[location])) end, 3000, 1, location) I start a map that has dxDrawText, and then wait 3 sec, but it still shows the text on screen. Link to comment
BinSlayer1 Posted February 27, 2012 Share Posted February 27, 2012 you're nil-ing the main function, but not everything it has fired since it was called.. It may have called some addEventHandler functions so you must use removeEventHandler I could be wrong Link to comment
arezu Posted February 27, 2012 Author Share Posted February 27, 2012 you're nil-ing the main function, but not everything it has fired since it was called.. It may have called some addEventHandler functions so you must use removeEventHandlerI could be wrong Yeah, i already know that i can do removeEventHandler, but i was just asking if there was an easier way than searching for all events and using removeEventHandler and killing all timers Link to comment
Kenix Posted February 27, 2012 Share Posted February 27, 2012 Believe me, you need to use loadstring only in extreme necessity. Why you use loadstring can you say? Link to comment
arezu Posted February 27, 2012 Author Share Posted February 27, 2012 Believe me, you need to use loadstring only in extreme necessity.Why you use loadstring can you say? I have a training gamemode (Race) and all players should be able to play on different maps. Link to comment
arezu Posted February 27, 2012 Author Share Posted February 27, 2012 I found another "easy" way to fix it.. thanks for the help anyways! (I replaced addEventHandler with addEventHandler2(my own custom function) and saved function names and event names and then remove events inside the script..) edit: Now i just want to know if its possible to loadstring from compiled script. Link to comment
Cadu12 Posted February 28, 2012 Share Posted February 28, 2012 It is possible make a protect file client. e.g |0154|4879|nameFunction|0144|0145|0153| -> function nameFunction() end Yes it is impossible for you. Link to comment
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