pro-mos Posted February 23, 2017 Share Posted February 23, 2017 (edited) I've edited bonsai's script wrapper and using it, it looks like this: local env = {} local _createObject = createObject local _setTimer = setTimer local _addEventHandler = addEventHandler outputChatBox = function() end triggerServerEvent = function() end createObject = function(...) local object = _createObject(...) setElementDimension(object, dimension) table.insert(wrapper.objects, object) return object end function newClientEnvironment() env = table.copy(_G, true) local metatable = { __index = function(self, index) return rawget(_G, index) end, __newindex = function(_G, index, value) rawset(_G, index, value) end } setmetatable(env, metatable) _outputChatBox('created new Environment') end and this is how a script is loaded: function loadScript(scriptData) local loaded = loadstring(scriptData) setfenv(loaded, env) local ex = pcall(loaded) end The problem is the functions re-defined above interfere with my main script that is using this wrapper. i can just use this wrapper as a separate script but then i'll have to reload two scripts rather than 1, and i dont want that. any ideas? and thank you for reading Edited February 23, 2017 by pro-mos Link to comment
pro-mos Posted February 24, 2017 Author Share Posted February 24, 2017 Bump @Solidsnake14 Link to comment
Bonsai Posted February 24, 2017 Share Posted February 24, 2017 What do you mean with "reload two scripts"? If you make it a seperate resource that only handles script loading there shouldn't be any problems, and I assume its safer too. Also, that script back then was pretty messy. And very important, don't use that for server side scripts. Link to comment
pro-mos Posted February 24, 2017 Author Share Posted February 24, 2017 16 minutes ago, Bonsai said: What do you mean with "reload two scripts"? If you make it a seperate resource that only handles script loading there shouldn't be any problems, and I assume its safer too. Also, that script back then was pretty messy. And very important, don't use that for server side scripts. Hi i would like it to be on the same resource, so when im testing, i /restart only 1 resource, i tried to insert the modified functions into 'env' like env.addEventHandler = ... env.outputChatbox = ... everytime the environment is created. but that doesn't work Link to comment
Bonsai Posted February 24, 2017 Share Posted February 24, 2017 If you do something like this in your main resource: <include resource="other_resource" /> then it will start and stop along with the main resource. I wouldn't do it in one big resource. Link to comment
pro-mos Posted February 24, 2017 Author Share Posted February 24, 2017 The metatable was causing the issue, removed it and now it works and one script. 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