Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to program with shared memory & threads?

As we all know, using spawn() will allow us to execute functions in parallel. However, how can we share memory so that what happens on one function can be checked by the other function?

I suppose one of the answer is using global scope variables with _G but this will make it global thru all scripts. What are some other ways and perhaps with more restricted scope?

1 comment

0

You could use RemoteFunctions or BindableFunctions to share values between scripts.

1 answer

You could use modulescripts for this. Unlike what KingLone said, you can not "share" variables with RemoteFunctions or BindableFunctions, only the values of those variables. You can create a module that returns variables, and only scripts that are able to require it will be able to acces- and change those values

For example, within a ModuleScript:

local module={

	a=true,
	b="hi!",
	c=4,

}

return module

Inside a serverscript:

local returnedTable=require(modulescript)

print(returnedTable.a)
print(returnedTable.b)
print(returnedTable.c)

This discussion is preserved as it was. New answers, comments, and votes are closed.