|
| 10 Nov 2016 11:05 PM |
| Just an update on how this whole script builder thing is actually going: Great, I even ########### a system that makes it so when you type in # ## it adds the second quotation, like a real code editor, same for (, it will add in the next ) |
|
|
| Report Abuse |
|
|
|
| 10 Nov 2016 11:29 PM |
ALSO, on the dictionary at the side, when you press what it says (example: script) then it adds that to the code block,
AND,
I added a backup script called "Main2" that's disabled, and if the other one is destroyed, then it clones Main2, names it Main, and undisables it, so the thing CANT be destroyed. |
|
|
| Report Abuse |
|
|
|
| 10 Nov 2016 11:32 PM |
| what if they destroy both lol |
|
|
| Report Abuse |
|
|
VilgO
|
  |
| Joined: 15 Feb 2011 |
| Total Posts: 518 |
|
|
| 11 Nov 2016 12:04 AM |
| What if I want to run custom code in a separate environment? Can I let it interact with the game through a custom module without inserting said module as text into every script? |
|
|
| Report Abuse |
|
|
VilgO
|
  |
| Joined: 15 Feb 2011 |
| Total Posts: 518 |
|
|
| 11 Nov 2016 12:11 AM |
| To be clear what I want is to create my own ModuleScript (let's name it apimodule) and allow players to use it in their scripts instead of giving them direct access to everything. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 11 Nov 2016 12:16 AM |
| So you want them to be able to only call the functions in your module and not everything else? |
|
|
| Report Abuse |
|
|
|
| 11 Nov 2016 12:18 AM |
| setfenv(0,require(myModule)) |
|
|
| Report Abuse |
|
|
|
| 11 Nov 2016 12:20 AM |
you can add that to the string or also use it on the function before running it
loadstring("setfenv(0,require(myModule)); "..code)
local func = loadstring(code) setfenv(func,myModule) |
|
|
| Report Abuse |
|
|
|
| 11 Nov 2016 12:21 AM |
setfenv(func,require(myModule)) * |
|
|
| Report Abuse |
|
|
VilgO
|
  |
| Joined: 15 Feb 2011 |
| Total Posts: 518 |
|
|
| 11 Nov 2016 12:26 AM |
Thanks, looks like exactly what I need. Is there an easy way to populate the new environment with safe functions like pairs()? |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 11 Nov 2016 12:29 AM |
You don't need that setfenv(0, ...) part, ignore him.
And if you want a whitelist you'll have do manually do it, i.e. either add it to the myModule table or have the myModule table fallback to the whitelsit. |
|
|
| Report Abuse |
|
|
|
| 11 Nov 2016 12:31 AM |
--you can do this
local No_Send = { "print"=true; }
local Send = {} for k,v in next,_G do if not No_Send[k] then Send[k]=v --to clone table end end
return Send |
|
|
| Report Abuse |
|
|
|
| 11 Nov 2016 12:32 AM |
you need to change the environment if you want to disallow it though :/
ex:
setfenv(0,{})
print("hi") --attempt to call a nil value
|
|
|
| Report Abuse |
|
|
|
| 11 Nov 2016 12:33 AM |
| the other was just me attaching it to the code |
|
|
| Report Abuse |
|
|
|
| 11 Nov 2016 12:34 AM |
| and the problem with this tho is that they can always just use _G instead |
|
|
| Report Abuse |
|
|
|
| 11 Nov 2016 12:35 AM |
| unless you also get rid of _G from the env :P |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 11 Nov 2016 12:35 AM |
"you need to change the environment if you want to disallow it though :/" That's what "setfenv(func,require(myModule))", do you seriously not know anything about environments
"and the problem with this tho is that they can always just use _G instead" In Roblox, _G is not a reference to the global envirnoment anyways. |
|
|
| Report Abuse |
|
|
|
| 11 Nov 2016 12:36 AM |
^ flux both of them would do the same thing, setting the fenv of the function in the ways that i used them did you not see i was the one who posted both? lmao |
|
|
| Report Abuse |
|
|
|
| 11 Nov 2016 12:38 AM |
| where do all of the globals come from then? |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 11 Nov 2016 12:39 AM |
"where do all of the globals come from then?" I already explained this hundreds of times.
Roblox encapsulates them in the metatable of all scripts' environments
|
|
|
| Report Abuse |
|
|
|
| 11 Nov 2016 12:40 AM |
you didnt say that yet to me
so getmetatable(script) ? |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 11 Nov 2016 12:40 AM |
no lol. getmetatable(getfenv()).__index
All scripts' environment have the same metatable (obv. you can change the env using setfenv) |
|
|
| Report Abuse |
|
|
|
| 11 Nov 2016 12:41 AM |
| sadly its locked too so im guessing you would need a whitelist |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 11 Nov 2016 12:42 AM |
| i can still dump all the contents of it here if you want me to so you can decide what to whitelist |
|
|
| Report Abuse |
|
|
|
| 11 Nov 2016 12:51 AM |
| already is a wiki page of them i can bet |
|
|
| Report Abuse |
|
|