跳到主要内容

Storage:read()

通过键读取一个已存储的值。

参数

参数类型描述
keystring存储键

签名

Storage:read(key: string): string | nil

返回值

string | nil - 以字符串形式返回已存储的值,当找不到键时返回 nil

描述

Storage:read() 以文本形式返回已存储的值。数值和布尔值也会以字符串形式返回。

示例

local username = Storage:read("username")
if username ~= nil then
print(username)
end
local retryCount = Storage:read("retry_count")
if retryCount ~= nil then
local count = tonumber(retryCount)
print(count)
end

说明

  • 不存在的键返回 nil
  • 已存储的数值和布尔值会以字符串形式返回
  • 键不能为空