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
 

Textbox that executes code that you type in it?

Previous Thread :: Next Thread 
DaCrazyDev is online. DaCrazyDev
Joined: 28 Sep 2013
Total Posts: 134
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
DaCrazyDev is online. DaCrazyDev
Joined: 28 Sep 2013
Total Posts: 134
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
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
10 Nov 2016 11:32 PM
what if they destroy both lol
Report Abuse
VilgO is not online. 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 is not online. 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 is not online. 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
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
11 Nov 2016 12:18 AM
setfenv(0,require(myModule))
Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
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
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
11 Nov 2016 12:21 AM
setfenv(func,require(myModule))
*
Report Abuse
VilgO is not online. 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 is not online. 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
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
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
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
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
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
11 Nov 2016 12:33 AM
the other was just me attaching it to the code
Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
11 Nov 2016 12:34 AM
and the problem with this tho is that they can always just use _G instead
Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
11 Nov 2016 12:35 AM
unless you also get rid of _G from the env :P
Report Abuse
cntkillme is not online. 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
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
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
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
11 Nov 2016 12:38 AM
where do all of the globals come from then?
Report Abuse
cntkillme is not online. 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
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
11 Nov 2016 12:40 AM
you didnt say that yet to me

so
getmetatable(script)
?
Report Abuse
cntkillme is not online. 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
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
11 Nov 2016 12:41 AM
sadly its locked too so im guessing you would need a whitelist
Report Abuse
cntkillme is not online. 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
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
11 Nov 2016 12:51 AM
already is a wiki page of them i can bet
Report Abuse
Previous Thread :: Next Thread 
Page 2 of 3Go to page: 1, [2], 3 Prev Next
 
 
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