1

self.character.data().bank即使使用该函数,我如何对类的所有实例进行相同的处理setBank?目前在使用它时,如果有意义setBank,只会在一个实例上更新self.character.data().bank

_G.GetUser = {
    users = {},
    users_group = {},
    userData = {},
    CurrentCharacter = {}
}

_G.GetUserMethods = {}

GetUserMethods.__call = function(self, source)
    local o = setmetatable({}, {
        __index = self
    })

    o.src = source

    o.id = self.users[o.src]

    o.rank = self.users_group[o.src]

    return o
end

GetUserMethods.__index = {
    getCurrentCharacter = function(self)
        self.character = {}

    self.character.id = self.CurrentCharacter[self.id]

    self.character.data = function()
        return self.userData[self.character.id]
    end

    self.character.setBank = function(v)
        if self.character.data() then
            self.character.data().bank = v
        end
    end
        
    self.character.getBank = function()
        if self.character.data() then
            return self.character.data().bank
        end
        
        return nil
    end

        return self.character
    end
}

setmetatable(GetUser, GetUserMethods)
4

1 回答 1

0

代替

importClass {'getuser'}

if not _G.GetUser then
   importClass {'getuser'}
end

在每个文件中。

于 2020-12-22T11:22:10.543 回答