|
| 07 Jun 2016 12:19 PM |
| Sometimes when I create a module, I just do it so I can segment my code more and make it more readable. The problem with a module is that unlike code within its home script, it doesn't have access to all the variables. I can manually insert the ones I need with parameters, but I'm wonder if there's a method to just send the whole scope of variables to a module, almost as if it was just contained within the same script that's using require() on it. |
|
|
| Report Abuse |
|
|
|
| 07 Jun 2016 12:23 PM |
ermm...
Just assign single table and type all your values inside |
|
|
| Report Abuse |
|
|
|
| 07 Jun 2016 12:24 PM |
You need getfenv, which takes a function's environment (i.e. all variables the function has access to) and send them in a table.
http://wiki.roblox.com/index.php?title=Function_dump/Basic_functions#getfenv |
|
|
| Report Abuse |
|
|
|
| 07 Jun 2016 12:26 PM |
| It would erase old variables since your chancing environment or not ? |
|
|
| Report Abuse |
|
|
|
| 07 Jun 2016 12:47 PM |
| Nope, erasing old variables would be setfenv (I think). |
|
|
| Report Abuse |
|
|
|
| 07 Jun 2016 12:48 PM |
| Also while I'm posting here, congrats on getting your account back badgraphix ;D |
|
|
| Report Abuse |
|
|
|
| 07 Jun 2016 03:14 PM |
You can't use getfenv in this case, because that returns the function environment (the GLOBAL VARIABLES of that function). If you wanted to do that you would have to make all the variables global AND give the function its own environment (that ofc. should fallback to the original one) so your new globals don't clutter up the global environment.
local function sendExample() var1 = 5 var2 = 10 var3 = 20 blahblah(getfenv()) -- send the table of globals end
setfenv(sendExample, setmetatable({}, {__index=getfenv()}))
If you wanted to send all the values alone, not the table of globals, you'd have to iterate over the environment and pack the values into an array and unpack the array.
The better solution would be to just put all the variables into a table or just know the name of the variables and send them explicitly. |
|
|
| Report Abuse |
|
|
|
| 08 Jun 2016 08:53 AM |
| Aw, that's unfortunate. I'm guessing it's unlikely we'll get a built-in function for this type of thing in the future. |
|
|
| Report Abuse |
|
|
|
| 08 Jun 2016 02:51 PM |
| I mean there _sort of_ is a built in feature, but it only exists in vanilla Lua and it's definitely not meant for this. Roblox removed almost everything from the debug library so yeah |
|
|
| Report Abuse |
|
|