问题描述
我如何使 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)
解决方法
替换
importClass {'getuser'}
与
if not _G.GetUser then
importClass {'getuser'}
end
在每个文件中。