Is there any way to modify what the module will return in Lua?

1

I want to know if it exists since I have a data storage system, in which the data is in a table and when the player enters, that data is stored in a module script (The only one that returns something) . The problem is that you can not keep typing for example:

inventory=require(inventory)
inventory.Knifes=async.Knifes
inventory.ChosenKnife=async.ChosenKnife
inventory.Citrines=async.Citrines
--...

I've already tried

require(inventory)=async

But it made a mistake. Appeared "Expected identifier, got="

Please help me, I have little time!

Here's the block I'm working on:

dss=game:GetService('DataStoreService'):GetDataStore('GameStuff')

game.Players.PlayerAdded:connect(function(player)
    local key='id='..player.userId
    local async=dss:GetAsync(key)
    if not async then
        local save={Knifes={1},ChosenKnife=1,Citrines=,Coins=0}
        dss:SetAsync(key,save)
        async=dss:GetAsync(key)
    end
    local module=script.ModuleScript:Clone()
    module.Parent=player:WaitForChild'PlayerGui'
    --Modificar o valor retornado de module
end
    
asked by anonymous 14.04.2017 / 01:08

1 answer

1

I think it would be easier to adapt a class to your inventory module. Otherwise, it seems that it is only possible to update the value of a module in Lua versions larger than 5.0, by accessing the package.loaded table, in which its required module would be the 'inventory' field, for example:

package.loaded.inventory = async

Perhaps the inventory module is unnecessary, if inventory == async ( package.loaded.inventory will point to the same async table, as in its last example as corrected above).

    
15.04.2017 / 20:20