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
 

Re: Using ModuleScripts to store temp data?

Previous Thread :: Next Thread 
filiptibell is not online. filiptibell
Joined: 10 Mar 2013
Total Posts: 2362
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 is not online. 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
filiptibell is not online. filiptibell
Joined: 10 Mar 2013
Total Posts: 2362
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 is not online. 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 is not online. 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
fishguy100 is not online. fishguy100
Joined: 16 Feb 2013
Total Posts: 3679
09 Feb 2015 06:42 PM
use a remotefunction with it to transfer the vale...
Report Abuse
filiptibell is not online. filiptibell
Joined: 10 Mar 2013
Total Posts: 2362
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
fishguy100 is not online. fishguy100
Joined: 16 Feb 2013
Total Posts: 3679
09 Feb 2015 06:46 PM
USE REMOTEFUNCTIONS ITS THE PROFESSIONAL WAY
Report Abuse
filiptibell is not online. filiptibell
Joined: 10 Mar 2013
Total Posts: 2362
09 Feb 2015 06:47 PM
@fishguy
Could you stop trolling, please...

~The herp lerped a derp~
Report Abuse
mew903 is not online. 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
KOTwarrior is not online. KOTwarrior
Joined: 13 Jun 2012
Total Posts: 4376
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
filiptibell is not online. filiptibell
Joined: 10 Mar 2013
Total Posts: 2362
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
KOTwarrior is not online. KOTwarrior
Joined: 13 Jun 2012
Total Posts: 4376
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
KOTwarrior is not online. KOTwarrior
Joined: 13 Jun 2012
Total Posts: 4376
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
filiptibell is not online. filiptibell
Joined: 10 Mar 2013
Total Posts: 2362
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
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