|
| 25 May 2015 05:49 PM |
So for example, if I was to type:
setfenv(0,{}) print("Hi")
into the command bar, I would get an error about print not existing, which means it works.
However, if I type: print("Hi") again, it works just fine. Why is this? |
|
|
| Report Abuse |
|
|
|
| 25 May 2015 05:52 PM |
| Idk I'm learning scripting, any advice? Or sources I could use? Anything is appreciated. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 25 May 2015 05:53 PM |
| Well the command bar is just loadstring'd so doing that you aren't actually changing the env. of the command bar. |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 25 May 2015 05:55 PM |
Quick, pcall(getfenv)
There's a problem with pcalling getfenv, in that it doesn't behave right. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 25 May 2015 06:01 PM |
| I don't think it's really a problem, just how getfenv and pcall work. |
|
|
| Report Abuse |
|
|
|
| 25 May 2015 06:06 PM |
@cnt But it still stores variables in a table environment, and Im trying to change that environment to the corescript environment. Don't ask how, but I have access to it lol.
|
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 25 May 2015 06:09 PM |
Well yeah the environment is the global environment for loadstring, so:
loadstring("x = 5;")() would add it to the global environment, no matter if the function it was called in had a different environment.
local test = function() loadstring("x = 5;")(); print(x); -- nil end;
setfenv(test, {loadstring=loadstring;print=print;}); test(); print(x); -- 5
That should print what I commented (inb4spellingerror) |
|
|
| Report Abuse |
|
|
|
| 25 May 2015 06:11 PM |
Oh wow. Yeah that might work lol.
|
|
|
| Report Abuse |
|
|
Froast
|
  |
| Joined: 12 Mar 2009 |
| Total Posts: 3134 |
|
|
| 25 May 2015 06:14 PM |
| The Command Bar uses game.LogService.ExecuteScript |
|
|
| Report Abuse |
|
|
|
| 25 May 2015 06:15 PM |
^ That's for the in-game console that allows the client to request for the server to execute code. |
|
|
| Report Abuse |
|
|
Froast
|
  |
| Joined: 12 Mar 2009 |
| Total Posts: 3134 |
|
|
| 25 May 2015 06:21 PM |
| Which command bar wasn't specified, I should've assumed it was the studio one though. |
|
|
| Report Abuse |
|
|