KV.Get(PlayIndex, Key)

函数功能

获取目标玩家的指定属性值。

操作参数

参数名 是否必须 类型 说明
PlayIndex int 玩家对象索引
Key string 属性名称

返回值

返回值类型由存储时的值决定(字符串、整数、布尔、数组等)。

  • 若 Key 不存在或未设定值:
    • 当期望值为字符串类型时,返回空字符串 ""
    • 当期望值为整数类型时,返回 nil
  • 若 Key 存在,则返回存储的实际值(类型保持不变)。

建议:在 Lua 中可通过 type(KV.Get(PlayIndex, Key)) 判断返回类型,或直接与 nil 比较。

操作示例


-- 字符串类型(不存在时返回 ""local name = KV.Get(PlayIndex, "name")
if name == "" then
    print("名字未设置")
else
    print("名字:" .. name)
end

-- 整数类型(不存在时返回 nil)
local level = KV.Get(PlayIndex, "level")
if level == nil then
    print("等级不存在")
else
    print("等级:" .. level)
end

-- 布尔类型
local isVip = KV.Get(PlayIndex, "isVip")
if isVip == true then
    print("VIP用户")
end

-- 数组类型
local skills = KV.Get(PlayIndex, "skills")
if skills then
    for i, v in ipairs(skills) do
        print("技能:" .. v)
    end
end
作者:105493660  创建时间:2026-05-02 16:49
最后编辑:105493660  更新时间:2026-05-02 18:35