✓ Accepted answer
local module = {Letters, OrderedLetters} creates a list where the first item is whatever Letters refers to and the second item is whatever OrderedLetters refers to. The way you are trying to use it, you want to do this instead:
local module = {
Letters = Letters,
OrderedLetters = OrderedLetters,
}
Note that "variables" cannot be passed or shared with module scripts, only values. This distinction is important. Here's an illustration:
local module = {num = 1}
function module:Inc()
self.num += 1
end
return module
local module = require(script.Module)
local var = module.num
print("start:", var, module.num)
module:Inc()
print("after Inc:", var, module.num)
var = 5
print("after var = 5:", var, module.num)
The point is that the num variable is not shared, only the value referenced by num. This normally shouldn't be a problem: you can just access module.num to get the latest value. In the event you have some code where you need to effectively share a "variable", you can sort of accomplish this by wrapping it in a table (but this means that all the code has to expect that it'll be dealing with a table containing the desired value rather than the value itself). For example:
local function inc(v)
v += 1
end
local num = 1
inc(num)
print(num)
local function inc(v)
v[1] += 1
end
local num = {1}
inc(num)
print(num[1])
Superior alternatives that will work most of the time:
- As mentioned above, just use
module.num or module:GetNum()
- Have
inc return the new value (the code might look like num = inc(num))
1 comment
I don't really understand. You did not assign a value to the variables inside the module, thus returning nil. What is your goal here?