Appearance
二维表变量数据管理接口 Table
具体函数名及描述如下:
| 序号 | 函数名 | 函数描述 |
|---|---|---|
| 1 | UpdateAllValue(...) | 更新整个表的数据信息 |
| 2 | Clear(...) | 清理表格数据 |
| 3 | InsertValue(...) | 在末尾插入一行数据 |
| 4 | InsertValueByRow(...) | 在某行插入一行数据 |
| 5 | GetValue(...) | 获取表格数据 |
| 6 | GetAllValue(...) | 获取表格数据 |
| 7 | SetValue(...) | 设置表格数据 |
| 8 | RemoveRow(...) | 删除序列号的值 |
| 9 | GetValuesByCol(...) | 获取某列的所有值 |
| 10 | GetRows(...) | 获取行数 |
| 11 | GetCols(...) | 获取列数 |
| 12 | GetColIndex(...) | 获取列索引 |
| 13 | GetRowIndex(...) | 获取指定列和值的行索引(默认判断值相等) |
| 14 | GetRowIndexs(...) | 获取指定列和值的所有行索引(默认判断值相等) |
| 15 | GetTableColKeys(...) | 获取表格列的key |
UpdateAllValue
- 参数及类型:
- 返回值及类型:
- ret:
bool是否成功
- ret:
- 该方法的主要作用: 更新整个表的数据信息
- 具体使用案例如下:
lua
local ret = Data.Table:UpdateAllValue(varId, playerId, value)Clear
lua
local isSuccess = Data.Table:Clear(varId)
if isSuccess then
print("清除表格成功")
end
local isSuccessPlayer = Data.Table:Clear(playerVarId, Player:GetHostUin())
if isSuccessPlayer then
print("清除玩家表格成功")
endInsertValue
- 参数及类型:
- 返回值及类型:
- ret:
bool是否成功
- ret:
- 该方法的主要作用: 在末尾插入一行数据
- 具体使用案例如下:
lua
-- 传参规则(变量id , 玩家uin(全局传nil), 第一列填充数据, 第二列填充数据, 第三列填充数据,...)
local isSuccess = Data.Table:InsertValue(varId, nil, 2, "aa", false)
if isSuccess then
print("插入表格值成功")
end
-- 传参规则(变量id , 玩家uin(全局传nil), 第一列填充数据, 第二列填充数据, 第三列填充数据,...)
local isSuccessPlayer = Data.Table:InsertValue(playerVarId, Player:GetHostUin(), 2, "aaa", false)
if isSuccessPlayer then
print("插入玩家表格值成功")
endInsertValueByRow
- 参数及类型:
- 返回值及类型:
- ret:
bool是否成功
- ret:
- 该方法的主要作用: 在某行插入一行数据
- 具体使用案例如下:
lua
local data = {
[1] = 2, -- 第一列填充的数据
[2] = "sss3", -- 第二列填充的数据
[3] = false, -- 第三列填充的数据
-- [4] = {x = 1,y = 7,z = 1}, -- 第四列填充的数据
-- 。。。。。 根据实际变量的列类型填充
}
local isSuccess = Data.Table:InsertValueByRow(varId, nil, data, 1) -- 在第一行插入一行数据
if isSuccess then
print("按行插入表格值成功")
end
local data2 = {
[1] = 2, -- 第一列填充的数据
[2] = "sssa", -- 第二列填充的数据
[3] = false, -- 第三列填充的数据
-- [4] = {x = 1,y = 7,z = 1}, -- 第四列填充的数据
-- 。。。。。 根据实际变量的列类型填充
}
local isSuccessPlayer = Data.Table:InsertValueByRow(playerVarId, Player:GetHostUin(), data2) -- 在最后一行插入一行数据
if isSuccessPlayer then
print("按行插入玩家表格值成功")
endGetValue
- 参数及类型:
- 返回值及类型:
- value:any返回的值
- 该方法的主要作用: 获取表格数据
- 具体使用案例如下:
lua
local value = Data.Table:GetValue(varId, nil, 2, 2)
if value then
print("获取表格值", value)
end
local playerValue = Data.Table:GetValue(playerVarId, Player:GetHostUin(), 2, 1)
if playerValue then
print("获取玩家表格值", playerValue)
endGetAllValue
- 参数及类型:
- 返回值及类型:
- value:
table返回的值
- value:
- 该方法的主要作用: 获取表格数据
- 具体使用案例如下:
lua
-- 获取后的数据格式是
-- {
-- {10, "RRR", 0},-- 第一行
-- {9, "sss", 0}, -- 第二行
-- {0, "fff", 0}, -- 第三行
-- }
local allValues = Data.Table:GetAllValue(varId)
if allValues then
print("获取表格所有值", allValues)
end
local playerAllValues = Data.Table:GetAllValue(playerVarId, Player:GetHostUin())
if playerAllValues then
print("获取玩家表格所有值", playerAllValues)
endSetValue
- 参数及类型:
- 返回值及类型:
- ret:
bool成功(true)
- ret:
- 该方法的主要作用: 设置表格数据
- 具体使用案例如下:
lua
local ret = Data.Table:SetValue(varId, playerId, row, col, value)RemoveRow
- 参数及类型:
- 返回值及类型:
- ret:
bool成功(true)
- ret:
- 该方法的主要作用: 删除序列号的值
- 具体使用案例如下:
lua
local isSuccess = Data.Table:RemoveRow(varId, nil, 1) -- 移除第一行
if isSuccess then
print("移除表格行成功")
end
local isSuccessPlayer = Data.Table:RemoveRow(playerVarId, Player:GetHostUin(), {2, 4}) -- 移除第二行和第四行
if isSuccessPlayer then
print("移除玩家表格行成功")
endGetValuesByCol
- 参数及类型:
- 返回值及类型:
- ret:
bool成功(true)
- ret:
- 该方法的主要作用: 获取某列的所有值
- 具体使用案例如下:
lua
local values = Data.Table:GetValuesByCol(varId, nil, 1)
if values then
print("获取表格列值", values)
end
local playerValues = Data.Table:GetValuesByCol(playerVarId, Player:GetHostUin(), 2)
if playerValues then
print("获取玩家表格列值", playerValues)
endGetRows
lua
local rows = Data.Table:GetRows(varId)
if rows then
print("获取表格行数",rows)
end
local size = Data.Table:GetRows(playerVarId, Player:GetHostUin())
if size then
print("获取玩家表格行数",size)
endGetCols
lua
local cols = Data.Table:GetCols(varId)
if cols then
print("获取表格列数",cols)
end
local num = Data.Table:GetCols(playerVarId, Player:GetHostUin())
if num then
print("获取玩家表格列数",num)
endGetColIndex
lua
local colIndex = Data.Table:GetColIndex(varId, nil, "名称")
if colIndex then
print("获取表格列索引", colIndex)
end
local playerColIndex = Data.Table:GetColIndex(playerVarId, Player:GetHostUin(), "分数")
if playerColIndex then
print("获取玩家表格列索引", playerColIndex)
endGetRowIndex
- 参数及类型:
- 返回值及类型:
- size:
number行数
- size:
- 该方法的主要作用: 获取指定列和值的行索引(默认判断值相等)
- 具体使用案例如下:
lua
local rowIndex = Data.Table:GetRowIndex(varId, nil, 2, "sss")
if rowIndex then
print("获取表格行索引", rowIndex)
end
local playerRowIndex = Data.Table:GetRowIndex(playerVarId, Player:GetHostUin(), 3, true)
if playerRowIndex then
print("获取玩家表格行索引", playerRowIndex)
endGetRowIndexs
- 参数及类型:
- 返回值及类型:
- size:
number行数
- size:
- 该方法的主要作用: 获取指定列和值的所有行索引(默认判断值相等)
- 具体使用案例如下:
lua
local rowIndexs = Data.Table:GetRowIndexs(varId, nil, 2, "sss")
if rowIndexs then
for key, value in pairs(rowIndexs) do
print("获取表格行索引", value )
end
end
local playerRowIndexs = Data.Table:GetRowIndexs(playerVarId, Player:GetHostUin(), 3, false)
if playerRowIndexs then
for key, value in pairs(playerRowIndexs) do
print("获取玩家表格行索引", value )
end
endGetTableColKeys
lua
local colKeys = Data.Table:GetTableColKeys(varId)