|
| 09 Feb 2015 06:19 PM |
I've heard of people doing this, but how? Could anyone give an example?
~The herp lerped a derp~ |
|
|
| Report Abuse |
|
|
mew903
|
  |
| Joined: 03 Aug 2008 |
| Total Posts: 22071 |
|
|
| 09 Feb 2015 06:29 PM |
sounds pretty inefficient, but this is the only thing I can think of considering your post is so vague
-- modulescript
databank = { };
function store(key, val) databank[key] = val; end;
function get(key) local dat = databank[key]; databank[key] = nil; return dat; end;
return {store = store; get = get};
-- script
local databank = require(workspace.ModuleScript);
databank.store("tmpname", "hello");
print(databank.get("tmpname")); |
|
|
| Report Abuse |
|
|
|
| 09 Feb 2015 06:34 PM |
What I've tried doing is this:
local Quest = {}
Quest.Amount = 0
return Quest
But changing Quest.Amount through a script that has required the module doesn't seem to, well, save... Do modulescripts return copies of tables, or what's going on here?
~The herp lerped a derp~ |
|
|
| Report Abuse |
|
|
mew903
|
  |
| Joined: 03 Aug 2008 |
| Total Posts: 22071 |
|
|
| 09 Feb 2015 06:39 PM |
| That's why you have to call a function that changes the value locally from the modulescript |
|
|
| Report Abuse |
|
|
Juddily
|
  |
| Joined: 24 Aug 2008 |
| Total Posts: 4243 |
|
|
| 09 Feb 2015 06:40 PM |
| Changes made to returned values don't copy back over to the modulescript. |
|
|
| Report Abuse |
|
|
|
| 09 Feb 2015 06:42 PM |
| use a remotefunction with it to transfer the vale... |
|
|
| Report Abuse |
|
|
|
| 09 Feb 2015 06:44 PM |
I see. So using something like this would work, yes?
Quest.Get = function(Key) return Quest[Key] end
Quest.Set = function(Key, Value) Quest[Key] = Value return Quest[Key] end
~The herp lerped a derp~ |
|
|
| Report Abuse |
|
|
|
| 09 Feb 2015 06:46 PM |
| USE REMOTEFUNCTIONS ITS THE PROFESSIONAL WAY |
|
|
| Report Abuse |
|
|
|
| 09 Feb 2015 06:47 PM |
@fishguy Could you stop trolling, please...
~The herp lerped a derp~ |
|
|
| Report Abuse |
|
|
mew903
|
  |
| Joined: 03 Aug 2008 |
| Total Posts: 22071 |
|
|
| 09 Feb 2015 06:54 PM |
I strongly disagree with using remotefunctions here. They tend to create a lot of latency issues if you plan on using them a lot.
But yes, the way you posted would most likely work. Please experiment for yourself though =) |
|
|
| Report Abuse |
|
|
|
| 09 Feb 2015 07:30 PM |
@Jud I thought it would; considering the variable in your script which requires the module is just a pointer to the module. I would think the only way it wouldn't replicate all changes is if you require the module and then make a deep copy. |
|
|
| Report Abuse |
|
|
|
| 09 Feb 2015 07:34 PM |
@KOTwarrior
That's what I though as well, but I guess not... :P
~The herp lerped a derp~ |
|
|
| Report Abuse |
|
|
|
| 09 Feb 2015 07:37 PM |
No, I just did a test; the require just returns a pointer to the moduleScript's data. As long as you don't re-declare the variable every time it should work. Here's the test I did.
-- module
local a = {}; a.a = a.a or 0; return a;
-- script 1 (editer)
local a = require(workspace.testModule); a.a = 1;
-- script 2 (listener)
local a = require(workspace.testModule); wait(1); print(a); |
|
|
| Report Abuse |
|
|
|
| 09 Feb 2015 07:38 PM |
Whoops, forgot a key part.
-- module
local a = {}; a.a = a.a or 0; return a;
-- script 1 (editer)
local a = require(workspace.testModule); a.a = 1;
-- script 2 (listener)
local a = require(workspace.testModule); wait(1); print(a.a);
|
|
|
| Report Abuse |
|
|
|
| 09 Feb 2015 08:01 PM |
Yup, that's what I was doing. I was declaring a local variable within each function that required the module :P Ended up storing the information locally in the script and cloning the table instead, works fine ^^
~The herp lerped a derp~ |
|
|
| Report Abuse |
|
|