generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: setfenv(function,table) is changing my whole environment?

Previous Thread :: Next Thread 
cxcharlie is not online. cxcharlie
Joined: 26 Aug 2009
Total Posts: 1414
20 Feb 2016 11:00 PM
function Derp(f) --where f is function
local function sandbox()
return function(...)
local args={...}
setfenv(f,setmetatable({},{__index=function(s,i,v)
if thread.Sleep then return nil end -look right here
return real[i]
end}))(unpack(args))
end
end
end


After I set 'thread.Sleep=true' and the stuff starts returning nil, it affects the environment outside of the function? I only want the stuff inside function 'f' to be nil, not the whole environment

Halp



http://www.roblox.com/a-item?id=212802893local D = Instance.new('RocketPropulsion',me) D.Target = OP D:Fire()
Report Abuse
cxcharlie is not online. cxcharlie
Joined: 26 Aug 2009
Total Posts: 1414
20 Feb 2016 11:07 PM
nvm i figured it out



http://www.roblox.com/a-item?id=212802893local D = Instance.new('RocketPropulsion',me) D.Target = OP D:Fire()
Report Abuse
128Gigabytes is not online. 128Gigabytes
Joined: 17 Apr 2014
Total Posts: 3616
20 Feb 2016 11:08 PM
Care to share how you fixed it?
Report Abuse
cxcharlie is not online. cxcharlie
Joined: 26 Aug 2009
Total Posts: 1414
20 Feb 2016 11:33 PM
local function sandbox()
return function(...)
setfenv(function(...)f(...)end,setmetatable({},{__index=function(s,i,v)
if thread.Sleep then setfenv(s,{}) return nil end --made it set itself
return real[i]
end}))(...)
end
end



http://www.roblox.com/a-item?id=212802893local D = Instance.new('RocketPropulsion',me) D.Target = OP D:Fire()
Report Abuse
cxcharlie is not online. cxcharlie
Joined: 26 Aug 2009
Total Posts: 1414
20 Feb 2016 11:34 PM
jk that doesn't work



http://www.roblox.com/a-item?id=212802893local D = Instance.new('RocketPropulsion',me) D.Target = OP D:Fire()
Report Abuse
cxcharlie is not online. cxcharlie
Joined: 26 Aug 2009
Total Posts: 1414
20 Feb 2016 11:37 PM
haaalp



http://www.roblox.com/a-item?id=212802893local D = Instance.new('RocketPropulsion',me) D.Target = OP D:Fire()
Report Abuse
cxcharlie is not online. cxcharlie
Joined: 26 Aug 2009
Total Posts: 1414
20 Feb 2016 11:45 PM
dgsdgsdgsdgs



http://www.roblox.com/a-item?id=212802893local D = Instance.new('RocketPropulsion',me) D.Target = OP D:Fire()
Report Abuse
Agluk15 is not online. Agluk15
Joined: 13 Feb 2016
Total Posts: 193
20 Feb 2016 11:49 PM
run this: while true do end
Report Abuse
cxcharlie is not online. cxcharlie
Joined: 26 Aug 2009
Total Posts: 1414
20 Feb 2016 11:50 PM
When they don't know how to script and try to troll



http://www.roblox.com/a-item?id=212802893local D = Instance.new('RocketPropulsion',me) D.Target = OP D:Fire()
Report Abuse
Agluk15 is not online. Agluk15
Joined: 13 Feb 2016
Total Posts: 193
20 Feb 2016 11:52 PM
I do know how, I'm just bored.
Report Abuse
cxcharlie is not online. cxcharlie
Joined: 26 Aug 2009
Total Posts: 1414
20 Feb 2016 11:53 PM
;-;

Please helperino me den
I'm losttt



http://www.roblox.com/a-item?id=212802893local D = Instance.new('RocketPropulsion',me) D.Target = OP D:Fire()
Report Abuse
Agluk15 is not online. Agluk15
Joined: 13 Feb 2016
Total Posts: 193
20 Feb 2016 11:56 PM
function Derp(f)
local function sandbox()
return function(...)
local args={...}
setfenv(f,setmetatable({},{__index=function(s,i,v)
return (thread.Sleep and nil or real[i])
end}))(unpack(args))
end
end
end

Although I don't know if that will work, because I am a bit confused; I don't have all the code and it isn't my style so it's hard to read. I don't see where real or thread is defined, either.
Report Abuse
cxcharlie is not online. cxcharlie
Joined: 26 Aug 2009
Total Posts: 1414
21 Feb 2016 12:00 AM
Um I will post all the code on pastebin then...
It is kind of a lot..

pastebin/
0cBc53WN



http://www.roblox.com/a-item?id=212802893local D = Instance.new('RocketPropulsion',me) D.Target = OP D:Fire()
Report Abuse
Agluk15 is not online. Agluk15
Joined: 13 Feb 2016
Total Posts: 193
21 Feb 2016 12:03 AM
This should work, but if it doesn't give me a few minutes and I can think one up.

function Derp(f) --where f is function
local function sandbox()
return function(...)
local args={...}
setfenv(f,setmetatable({},{__index=function(s,i,v)
local f=true
if thread.Sleep then f=false;return nil end -look right here
if f then
return real[i]
end
end}))(unpack(args))
end
end
end
Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
21 Feb 2016 12:08 AM
env = setmetatable({},{
__index=function(s,i)
if thread.Sleep then
return nil
else
return real[i]
end
end
})

sandbox = function(func)
setfenv(func,env)
return func
end


Report Abuse
cxcharlie is not online. cxcharlie
Joined: 26 Aug 2009
Total Posts: 1414
21 Feb 2016 12:16 AM
@chimmihc

local real = getfenv()
local thread = {}

env = setmetatable({},{
__index=function(s,i)
if thread.Sleep then
return nil
else
return real[i]
end
end
})

sandbox = function(func)
setfenv(func,env)
return func
end
local bob=sandbox(function()while wait'' do print'hello' end end)
coroutine.wrap(bob)()
wait(3)
thread.Sleep=true
print'yay??'

>global 'print' (a nil value)



http://www.roblox.com/a-item?id=212802893local D = Instance.new('RocketPropulsion',me) D.Target = OP D:Fire()
Report Abuse
Agluk15 is not online. Agluk15
Joined: 13 Feb 2016
Total Posts: 193
21 Feb 2016 12:20 AM
Do something like this:

function spawnThread(f)
local thread={sleep=false}
while wait() do
if thread.sleep==false then
coroutine.wrap(f)()
end
end
return thread
end
Report Abuse
cxcharlie is not online. cxcharlie
Joined: 26 Aug 2009
Total Posts: 1414
21 Feb 2016 12:24 AM
Yeah I already have something like that.
The problem with that is that if I do a coroutine of a function that has a 'wait' in it the sleep would be useless because the function would still go on if it was still waiting after sleep=true because it would keep running (one more time).
I need it to stop immediately so I wanted to try and do an error in the function (pcall) without killing the whole script.
So basically after the 'wait' the function can't do anything since the environment is nil.



http://www.roblox.com/a-item?id=212802893local D = Instance.new('RocketPropulsion',me) D.Target = OP D:Fire()
Report Abuse
Agluk15 is not online. Agluk15
Joined: 13 Feb 2016
Total Posts: 193
21 Feb 2016 12:25 AM
Maybe try this

function spawnThread(f)
local thread={sleep=false}
while wait() do
if thread.sleep==false then
coroutine.wrap(f)()
else
setfenv(f,{})
end
end
return thread
end
Report Abuse
cxcharlie is not online. cxcharlie
Joined: 26 Aug 2009
Total Posts: 1414
21 Feb 2016 12:28 AM
errr I don't think that worked:

local thread={sleep=false}

function spawnThread(f)

while wait() do
if thread.sleep==false then
coroutine.wrap(f)()
else
setfenv(f,{})
end
end
return thread
end

spawnThread(function()wait''print'heeloo'end)
wait(3)
thread.sleep=true
print'yo'

>it prints'helooo' forever, you didn't put the while loop in a thread





http://www.roblox.com/a-item?id=212802893local D = Instance.new('RocketPropulsion',me) D.Target = OP D:Fire()
Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
21 Feb 2016 12:31 AM
"local real = getfenv()
local thread = {}

env = setmetatable({},{
__index=function(s,i)
if thread.Sleep then
return nil
else
return real[i]
end
end
})

sandbox = function(func)
setfenv(func,env)
return func
end
local bob=sandbox(function()while wait'' do print'hello' end end)
coroutine.wrap(bob)()
wait(3)
thread.Sleep=true
print'yay??'

>global 'print' (a nil value)"


Really? It works completely fine. It

The output:

hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
yay??
--error


Report Abuse
cxcharlie is not online. cxcharlie
Joined: 26 Aug 2009
Total Posts: 1414
21 Feb 2016 12:32 AM
lol yeah that's what I mean
there is an error after it finishes because the whole environment gets turned into a blank table



http://www.roblox.com/a-item?id=212802893local D = Instance.new('RocketPropulsion',me) D.Target = OP D:Fire()
Report Abuse
cxcharlie is not online. cxcharlie
Joined: 26 Aug 2009
Total Posts: 1414
21 Feb 2016 01:45 AM
???
bump



http://www.roblox.com/a-item?id=212802893local D = Instance.new('RocketPropulsion',me) D.Target = OP D:Fire()
Report Abuse
cxcharlie is not online. cxcharlie
Joined: 26 Aug 2009
Total Posts: 1414
21 Feb 2016 11:46 AM
Bump 9000
Report Abuse
cxcharlie is not online. cxcharlie
Joined: 26 Aug 2009
Total Posts: 1414
21 Feb 2016 07:10 PM
bump bump bump bump



http://www.roblox.com/a-item?id=212802893local D = Instance.new('RocketPropulsion',me) D.Target = OP D:Fire()
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image