Skip to content

二维表变量数据管理接口 Table

具体函数名及描述如下:

序号函数名函数描述
1Clear(...)清理表格数据
2InsertValue(...)在末尾插入一行数据
3InsertValueByRow(...)在某行插入一行数据
4GetValue(...)获取表格数据
5GetAllValue(...)获取表格数据
6SetValue(...)设置表格数据
7RemoveRow(...)删除序列号的值
8GetValuesByCol(...)获取某列的所有值
9GetRows(...)获取行数
10GetCols(...)获取列数
11GetColIndex(...)获取列索引
12GetRowIndex(...)获取指定列和值的行索引(默认判断值相等)
13GetRowIndexs(...)获取指定列和值的所有行索引(默认判断值相等)
14GetTableColKeys(...)

Clear

  • 参数及类型:
    • varId:string表ID
    • playerId:number玩家uin(全局变量传nil)
  • 返回值及类型:
    • ret:bool是否成功
  • 该方法的主要作用: 清理表格数据
  • 具体使用案例如下:
lua
   local isSuccess = Data.Table:Clear(varId)

   if isSuccess then

       print("清除表格成功")

   end

   local isSuccessPlayer = Data.Table:Clear(playerVarId, Player:GetHostUin())

   if isSuccessPlayer then

       print("清除玩家表格成功")

   end

InsertValue

  • 参数及类型:
    • varId:string表ID
    • playerId:number玩家uin(全局变量传nil)
    • ...:any按照列顺序编写的值 中间值不能传nil
  • 返回值及类型:
    • value:any返回的值
  • 该方法的主要作用: 在末尾插入一行数据
  • 具体使用案例如下:
lua
    local isSuccess = Data.Table:InsertValue(varId, nil, 2, "aa", false)

    if isSuccess then

        print("插入表格值成功")

    end

    local isSuccessPlayer = Data.Table:InsertValue(playerVarId, Player:GetHostUin(), 2, "aaa", false)

    if isSuccessPlayer then

        print("插入玩家表格值成功")

    end

InsertValueByRow

  • 参数及类型:
    • varId:string表ID
    • playerId:number玩家uin(全局变量传nil)
    • value:table插入的值{[1] = xx
    • ...} or {[key] = xx
    • ...}
  • 返回值及类型:
    • value:any返回的值
  • 该方法的主要作用: 在某行插入一行数据
  • 具体使用案例如下:
lua
    local isSuccess = Data.Table:InsertValueByRow(varId, nil, {2, "sss3", false}, 1) -- 在第一行插入一行数据

    if isSuccess then

        print("按行插入表格值成功")

    end

    local isSuccessPlayer = Data.Table:InsertValueByRow(playerVarId, Player:GetHostUin(), {2, "sssa", false})-- 在最后一行插入一行数据

    if isSuccessPlayer then

        print("按行插入玩家表格值成功")

    end

GetValue

  • 参数及类型:
  • 返回值及类型:
    • 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)

    end

GetAllValue

  • 参数及类型:
    • varId:string表ID
    • playerId:number玩家uin(全局变量传nil)
  • 返回值及类型:
    • value:any返回的值
  • 该方法的主要作用: 获取表格数据
  • 具体使用案例如下:
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)

    end

SetValue

  • 参数及类型:
    • varId:string表ID
    • playerId:number玩家uin(全局变量传nil)
    • row:number,array行索引或行索引数组
    • col:number列索引或列名
    • value:any设置的值
  • 返回值及类型:
    • ret:bool成功(true)
  • 该方法的主要作用: 设置表格数据
  • 具体使用案例如下:
lua
local ret = Data.Table:SetValue(varId, playerId, row, col, value)

RemoveRow

  • 参数及类型:
    • varId:string表ID
    • playerId:number玩家uin(全局变量传nil)
    • row:number,array行索引或索引组
  • 返回值及类型:
    • ret:bool成功(true)
  • 该方法的主要作用: 删除序列号的值
  • 具体使用案例如下:
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("移除玩家表格行成功")

    end

GetValuesByCol

  • 参数及类型:
    • varId:string表ID
    • playerId:number玩家uin(全局变量传nil)
    • col:number列索引或列名
  • 返回值及类型:
    • ret:bool成功(true)
  • 该方法的主要作用: 获取某列的所有值
  • 具体使用案例如下:
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)

    end

GetRows

  • 参数及类型:
    • varId:string表ID
    • playerId:number玩家uin(全局变量传nil)
  • 返回值及类型:
  • 该方法的主要作用: 获取行数
  • 具体使用案例如下:
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)

    end

GetCols

  • 参数及类型:
    • varId:string表ID
    • playerId:number玩家uin(全局变量传nil)
  • 返回值及类型:
  • 该方法的主要作用: 获取列数
  • 具体使用案例如下:
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)

    end

GetColIndex

  • 参数及类型:
    • varId:string表ID
    • playerId:number玩家uin(全局变量传nil)
  • 返回值及类型:
  • 该方法的主要作用: 获取列索引
  • 具体使用案例如下:
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)

    end

GetRowIndex

  • 参数及类型:
    • varId:string表ID
    • playerId:number玩家uin(全局变量传nil)
    • col:number列索引或列名
    • value:any查询的值
    • cmp:function筛选函数(可为nil,function(action
    • value) return a == value end)
  • 返回值及类型:
  • 该方法的主要作用: 获取指定列和值的行索引(默认判断值相等)
  • 具体使用案例如下:
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)

    end

GetRowIndexs

  • 参数及类型:
    • varId:string表ID
    • playerId:number玩家uin(全局变量传nil)
    • col:number列索引或列名
    • value:any查询的值
    • cmp:function筛选函数(可为nil,function(action
    • value) return a == value end)
  • 返回值及类型:
  • 该方法的主要作用: 获取指定列和值的所有行索引(默认判断值相等)
  • 具体使用案例如下:
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

    end

GetTableColKeys

  • 参数及类型:

  • 返回值及类型:

  • 该方法的主要作用:

  • 具体使用案例如下:

lua
    local colKeys = Data.Table:GetTableColKeys(varId)