Jump to content

Loadstring


arezu

Recommended Posts

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

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
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
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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...